Jump to content

How to search with "find()" in all the languages?


donatas
 Share

Recommended Posts

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

Nice, @Zeka

I was curious and tried that out 🙂 

IuAXb7c.png

ybYlDXv.png

$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'");

NyJQdx6.png

  • Like 2
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...