Ivan Gretsky Posted November 14, 2014 Share Posted November 14, 2014 I am building a search with standard API selectors. Have faced a few confusing moments, so decided to share my experience with it. 1) In the default site profile the search is built with the ~= selector operator like this: $selector = "title|body~=$q, limit=50"; Let's assume that $q = "Process Wire" This does find pages with title or body fields containing both full words Process and Wire (disregarding the case of the letters). It would not find any pages with ProcessWire. That is expected. But if $q = "Process" it still won't find pages with ProcessWire as ~= looks only for full words. This is quite uncomfortable especially for fusional languages like Russian. 2) Nice way to go is to use *= instead like this: $selector = "title|body*=$q, limit=50"; This does find ProcessWire with $q = "Process". But it won't find Pro-Fields with $q = "Pro", as *= uses MySQL fulltext indexes. This index does not index short words (<4 letters or so by default). And the hyphen breaks complex words and makes both split parts index separately (see user comments here). So Pro never gets indexed as it is only 3 letters long. This *= selector operator also does not allow to serch for several separate words as ~= does with its limitations. 3) The slower but more advanced way is to use %= like this: $selector = "title|body%=$q, limit=50"; This would find Pro-Fields with $q = "Pro", but will work slower and still won't be able to search for several words in the same time. I did not find a way to search for several incomplete words in the same time. Seems like it is impossible to achieve with just one selector. Probably I would need to process the search input somehow and build a series of selectors. If someone have already done that I would be delighted to find out how. Good day! 3 Link to comment Share on other sites More sharing options...
Soma Posted November 14, 2014 Share Posted November 14, 2014 if(strpos($q, " ") !== false) $q = str_replace(" ", "|", $q); $result = $pages->find("template=basic-page, title|body%=$q"); 7 Link to comment Share on other sites More sharing options...
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