Jump to content

Recommended Posts

Posted

Hello!

I have pages that have separated fields for first name and last name.

I'm working on a search form that has one single input field, so that if someone search for "John Doe" it should find all pages that have "first_name = John" and "last_name=Doe" or, of course, "first_name=Doe" and "last_name=John".

What would be the best use of selectors and operators in this case?

I came up with

first_name=John|Doe, last_name=John|Doe

so that i should split the search key with |

I'm not sure this is the best solution.

What would you suggest?

Thank you!

  • Like 1
Posted

@Zeka 

this wont work because it means that either first_name or last_name has to contain all the words (john doe).

also something like this would be not exactly what you are looking for, i guess:

first_name|last_name=john|doe

...because it would also find "hans doe", "maria doe", "john müller" etc.

i think the best is to populate a hidden search index field with what you want, for example:

$wire->addHookAfter('Pages::saveReady', function($event) {
  $page = $event->arguments(0);
  if($page->template != "yourtemplate") return;

  $page->searchindex = "{$page->forename} {$page->surname} # {$page->surname} {$page->forename}";
});

and the selector

$pages->find('searchindex~=john doe');

 

  • Like 1
Posted
12 hours ago, verdeandrea said:

I came up with


first_name=John|Doe, last_name=John|Doe

so that i should split the search key with |

I'm not sure this is the best solution.

What would you suggest?

Looks fine to me.

  • Like 1
Posted

It would also find John John and doe doe, but I guess that's unlikely and negligible, so maybe it's the easiest solution :)

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
×
×
  • Create New...