Jump to content
verdeandrea

Selectors and operator for first name last name search

Recommended Posts

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

Share this post


Link to post
Share on other sites

Hi 

first_name|last_name~=John Doe

 

Share this post


Link to post
Share on other sites

@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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By snobjorn
      I have a website with multiple content types that I want to be accessible through search. I really like the live search on processwire.com, that sorts content types while typing. I tried to find the code to recreate this, with no luck. Does anyone know if this is jquery, specific jquery plugins, json/xml cached files, and what kind of PHP code is used? Any tip that point me in the right direction would be much apperciated.
      The search result listing seems fairly easy to create with sorting through parameters.
    • By Anders
      I want to allow full text search on my site. There is a very nice solution that comes right out of the box:
      $selector = "title|body~=$q, limit=50"; This works, but to make it even better I would want to give higher weight to pages where the search term occurs in the title, than if it just occurs in the body. After all, a page with the title "Wine from France" is probably the best match for the search "france wine". How do I accomplish this in ProcessWire?
      I can see three possible paths, but I am not very fond of any of them:
      Do a direct SQL query, circumventing the API, along these lines. But I would prefer to abstract away the database layout if at all possible. Use something like ElasticSearch, but to be honest that would be to complicated to set up and maintain in the long run. Make multiple lookups, first for matches in the title, then for matches in the body, and merge and sort in PHP. My suspicion is that this would get complicated quite quickly. For instance, how do you deal with a page that has two of the three search terms in the title and the third in the body? Is there a magic option four I should look into? Or are any of the above options better than the others? Any input is welcome!
    • By jds43
      Hello,
      I have a search page loosely based on Skyscrapers where I'm parsing a selector with options 'beds', 'bathrooms', 'size' fields. It is working well until I select 'Any' after I've run a search. This is where no results are returned (/?beds=&bathrooms=&size=&submit=). I want it to reset and show all results.
      I hope this isn't too vague.
       
    • By sww
      Hey there,
      i am trying to add a kind of "intelligent" search.
      Is there any way to ignore punctuation and extra chars.
      e.g.
      When I type "somebody elses" that I still get the result "SOMEBODY ELSE´S CAR, 2005"
      The problem is the extra ´ … if I don't type it I don't get the result.
      So far I am using %=query (which isn't enough, I know)
      So the idea would be something like that:
      $selector = "sanitize(title|text)%=$q, limit=50";
      I know, it's not gonna work like that … just to illustrate.
      Best,
      Stefan
×
×
  • Create New...