donatas Posted May 1, 2021 Share Posted May 1, 2021 Hello, how would I do a multi-language website search with just a selector? I have many multi-lang fields and I want to do a search through all of them at once and through all of their language values. Is there a "selector way" of doing this? Maybe something like `title|title:de|title:it`? It seems I have seen this somewhere a long time ago but can't find in any documentation or forum search... Or the only way of doing it is by running separate searches for each language with output formatting off and then consolidating it all in one single results array? Because I still want to give users a result, even if it is in another language than current $user. Visitors mostly will be searching for specific terms that are very similar in all languages, but might be not used in one language version of a single page, for example. Or the user might not have switched language tohis prefered and did the search first, etc.. (many use cases in my situation) Example: $pages->find('title~='.$q) - maybe different operator is needed? /en/search/?q=visit = 1 results /it/search/?q=visit = 0 results Thanks for any advice! Link to comment Share on other sites More sharing options...
Zeka Posted May 1, 2021 Share Posted May 1, 2021 2 Link to comment Share on other sites More sharing options...
bernhard Posted May 2, 2021 Share Posted May 2, 2021 Nice, @Zeka I was curious and tried that out ? $langIds = []; foreach($languages as $lang) $langIds[] = $lang->isDefault() ? '' : $lang->id; $field = "title"; $field = "$field.data".implode("|$field.data", $langIds); db($field, 'field selector'); db($pages->find("template=person,$field*=schön")->each('title'), "search 'schön'"); db($pages->find("template=person,$field*=beautiful")->each('title'), "search 'beautiful'"); 3 Link to comment Share on other sites More sharing options...
donatas Posted May 2, 2021 Author Share Posted May 2, 2021 Thank you @Zeka and @bernhard! Looks like something that should do the trick! Will try these out! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now