Jump to content

Per-word $selector for autocomplete search bar


Eunico Cornelius
 Share

Recommended Posts

I am trying to filter my $pages with a find($selector method). 

$matches = $pages->find($selector);

and this is an example of what my selector looks like

$selector = "include=all, title|body~=$q, limit=50";

In this case, it only searches according to the matching exact words.

For example:we search="art", the result="art times","these art",....

Is there any way to search based on the alphabet?

For example: we search="ab", the result="absolutely correct","abstract art",....

Link to comment
Share on other sites

Fuzzy matching like one is expecting nowadays of a good search field is actually quite difficult to do with mysql. If you need a fast search returning relevant content for such short search terms you're most often better served using something like elasticsearch or angolia.

  • Like 1
Link to comment
Share on other sites

On 4/6/2018 at 5:24 PM, DaveP said:

If I understand correctly, in your $selector, use body^=$q instead of body~=$q. (Note caret instead of tilde.)

See https://processwire.com/api/selectors/#operators

 I understand this part, and I have tried to do it with body^=$q, However in a search, this will only apply for the first part of the word. For example, if I have a question "What is the best pet" this will only work if I search for "wh" and it will not show if I even search for "best". I have read the documentation and body*=$q fits more for search queries. Thank you for you help :) . @DaveP @LostKobrakai

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...