verdeandrea Posted July 19, 2017 Posted July 19, 2017 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! 1
bernhard Posted July 19, 2017 Posted July 19, 2017 @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'); 1
Robin S Posted July 19, 2017 Posted July 19, 2017 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. 1
bernhard Posted July 20, 2017 Posted July 20, 2017 It would also find John John and doe doe, but I guess that's unlikely and negligible, so maybe it's the easiest solution
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