php - Efficient MySQL text search -


i have forum written in php using mysql, , i'd make forum search available. allow users search particular strings, filter on metadata post date , subject , on. metadata can efficiently searched because of these fields indexed, think primary use-case of course going normal text search, , without making use of metadata filters trim results.

after testing have found that, contrary people's setups, sql_calc_found_rows faster (approx 1.5x) doing query twice in order number of results, best query have is:

sql_calc_found_rows * blahblah content '%term%' limit whatever whatever; 

unsurprisingly, slow because has text-match every single forum post in database. there can improve on this? putting index on content (text) field when using like operator? how 1 this?

an index on column help, using operator, not when have wildcard @ start too. term% index beneficial, %term% not.

but instead, may have @ fulltext indexes. if add such index text field, mysql indexes separate words , allows kinds of search engine-like searches. search use match() ... against instead of like.

see docs: https://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html

disclaimer: suggest read documentation after first experimentation. fulltext indexes powerful still have limits.

fulltext indexes take quite space, , way built depends on core settings in mysql, may behave differently between local setup , server.

for instance, index complete words leave out short words , stop-words. also, because index words, won't able search parts of words. looking 'term' not find 'determine' out of box.

so make sure indexes can want, , if have shared hosting, make sure can configured , tuned way before large implementation.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -