Problem/Motivation
With Umami becoming multilingual #3037111: Import multilingual content into Umami - search should return only the results that are in current language.
Since Drupal core doesn't support such configuration, we should find a way to solve this.
This issue may be blocked by #3045362: Search for node content in current language or duplicates of each other.
Proposed resolution
I found a piece of code to modify search results to current language on https://www.expert-it.com/en/filter-search-results-language-selected-dru...
(didn't test it yet)
I found another code here https://www.drupal.org/project/drupal/issues/3005181
and added it to demo_umami.profile file.
(tested, it works!)
function demo_umami_query_search_node_search_alter(&$query) {
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
$query->condition('i.langcode', array($language, 'und', 'zxx'), 'IN');
}
Another question would be how much customization is OK for an 'out of the box' Drupal demo?
Remaining tasks
Choose the best solution and implement it.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | search-for-chocolate-in-both-languages.png | 110.1 KB | shaal |
| #2 | search-current-language-3041039-2.patch | 531 bytes | shaal |
Comments
Comment #2
shaalInitial patch, implementing search modifications.
A problem that needs to be resolved:
'Advanced search results' is not displaying the search result alteration of searching only in the current language, and marking a different language then current language ends up "Your search yielded no results."
Maybe it would be easier & better to modify the URL of the search result page?
for English:
/search/node?f[0]=language:en&keys=for Spanish:
/search/node?f[0]=language:es&keys=That way - there's less hacking, and advanced search result are showing the correct filters that are applied.
Comment #3
eli-tWe shouldn't provide custom functionality via code in Umami. It is to demonstrate what Drupal can do out of the box.
There are only exceptions for theming and the installation process.
Comment #4
gábor hojtsyAgree with @Eli-T.
Also how does the "error" look like, what happens when two are found of the same article/recipe translated?
Comment #5
shaal@gabor here's the screenshot of searching for 'chocolate', that has results i both English and Spanish:
Comment #6
gábor hojtsyYeah hm that is quite unfortunate.
What does advanced search do?
Given #1853536: Reintroduce Views integration for search.module (not supporting backlinks view) umami could be using views as a search facility, since the "search box" is exposed as a views filter, but that would not be so nice either. I tried looking for an existing issue to filter search results by language but did not yet find one.
Comment #7
jasonawantI added reference to #3045362: Search for node content in current language in the issue summary.
Comment #14
anybody