Jump to content

Search not returning 3-letter words


Macrura
 Share

Recommended Posts

Hi,

I'm using more or less the same search code as in the default profile, however when searching on words or combinations of words using 3 letters or less, there are no search results returned.

The site in question is a company who's name is 3 letters, and there are a lot of products that are between 1-3 characters. I'm guessing this is something to do with the whitelist, or sanitizer?

I'd like to be able to adjust the settings somewhere to allow for 3 letter words to be returned on a search.

TIA

Link to comment
Share on other sites

I think this is to with the way MySQL is searched and I believe you can change the minimum word length in your server settings. Not sure if this will affect PW's use of search though.

Edit: You'll also note for example that three-letter words are excluded on this forum.

  • Like 1
Link to comment
Share on other sites

This also from the API docs....

The *= and ~= rely upon MySQL fulltext indexes, which only index words of at least a certain length (configurable, but typically 4 characters). They also don't index common English words called stopwords. So while it's preferable to use *= and ~= for their speed, if you aren't getting the results you need, you should consider using %= instead (if you can handle the speed hit).

http://processwire.com/api/selectors/

  • Like 3
Link to comment
Share on other sites

You'd have to get into tens of thousands of pages, if not more, before you would be able to detect a speed difference. That's been my experience at least. MySQL has apparently optimized their LIKE terms very well, or have figured out how to optimize to an index when it's there. 

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

When I had ~= in my selector, The search didn't return any results for queries containing 3letter words (example: "tea" or "white tea". "white" worked fine)

Here's the trick: when changed to %=, the 3letter searches work fine, but phrases return no results (example: "white tea". "tea" works fine)

full query:

$matches = $pages->find("path|title|label|body%=$q, limit=50, sort=sort"); // label is my custom field

ideas?

Link to comment
Share on other sites

When I had ~= in my selector, The search didn't return any results for queries containing 3letter words (example: "tea" or "white tea". "white" worked fine)

I recommend adjusting your MySQL fulltext minimum indexed word length. Search this forum for "ft_min_word_len". 

Here's the trick: when changed to %=, the 3letter searches work fine, but phrases return no results (example: "white tea". "tea" works fine)

Phrases should work with %= but the phrase you are searching for would have to be identical to the words it matches. Meaning if you searched for "white tea", it would only match pages containing the phrase "white tea", and not pages that have the words "white" and "tea" separated. Another thing to mention is that your full query above included "path", which is not query-able since it is generated at runtime (not in the DB). You can make it query-able by installing the PagesPaths module included with the core, but I don't think it can be part of an OR "|" set of fields. I recommend removing "path" from your query logic, as chances are the path is based on the title anyway. It sounds to me like what you really want is the "~=" operator, which will match all the words regardless of where they appear in the copy. Given that, tweaking your MySQL fulltext minimum index size (ft_min_word_len) would be worthwhile. 

See more details about how the different operators work here:

http://processwire.com/api/selectors/#operators

Link to comment
Share on other sites

yeah, I included the 'path' and have PagePaths installed - the 'path' part is actually very important, as I have quite a lot of children - parent thing going on (it's a products page) i.e.:

Producer \ product_line \ product_name

And, actually, in my example "white tea" is the 'product line' part of the path

anyway, I was hoping for that soluton as I'm not sure if I know where to find this tweak for mySQL database :->

argh, more searching for me

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