Jump to content

Selector problems on API


apeisa
 Share

Recommended Posts

Is there some kind minimum length for selector? I have selector like this:

$people = $pages->find("template=person, title*=$name");

If $name is "Anu" then it doesn't find anything, although I have two pages with titles like "Anu Surname". When $name is "Heikki" it does find pages like "Heikki Surname".

Link to comment
Share on other sites

The reason that's happening is due to a MySQL setting called ft_min_word_len. By default, MySQL doesn't index words less than 4 characters. This only affects partial match selector operators like *= and ~=. If you use an exact match selector like =, then that should still work regardless of how short the word is because it uses the exact index rather than the fulltext index. Below are instructions on how to change MySQL's ft_min_word_len setting so that you can use it with words as few as 2 characters.

Before making these changes, it's good to know that this change affects all tables with fulltext indexes on the server (regardless of what database they are in). Such tables will need to be repaired after this change is made (to force them to rebuild their indexes). This is fairly simple if you have PHPMyAdmin, because you can just select all tables and choose "repair", without really worrying about whether it has a fulltext index or not. This is easy to do if you are running your own VPS or server, but may be challenging or impossible on a commercial web host (though some will have already done this).

To make MySQL index words down to 2 characters, a change needs to be made in MySQL in this file:

/etc/my.cnf (or wherever your mysql config file is located). Add the following to this file:

[mysqld]
ft_min_word_len=2

If [mysqld] is already there, then just add the ft_min_word_len=2 part.

Following that, MySQL needs to be restarted, so that it reloads it's configuration file. Once restarted, everything should be back online, but you will want to run the table repair to force rebuild of indexes before your 2-letter words will actually work.

REPAIR TABLE [table name] QUICK;

In the case of ProcessWire, I would rebuild all the field_* tables. If you are using PhpMyAdmin, just repair all of ProcessWire's tables to make it easy. Choose the checkbox for "check all" at the bottom. Then select "Repair" in the select box to the right of it.

Following that, you should be good to go with words down to 2 characters. If there are other (non ProcessWire) databases on the server, you may want to repair them too. If any are using fulltext indexes, those indexes will eventually get corrupted if not repaired. By corrupted, I don't mean data loss, I just mean that the index may not work properly until it's repaired.

Let me know if I can be of any help.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...