Php + Mysql: full text and grant search without server-side support

I am trying to add search support on my website (hosted on a shared web hosting ... hostgator.com) because I am looking for an open source solution for full-text and fax searches that do not require any server (except php and mysql).

I have already covered a number of solutions, such as Lucene, Solr, Sphinx, Zend Lucene, including Mysql Full Text Search Support. And also know that Solr is the best solution for such things. But, as I said, my site is hosted on a shared web host without administrator rights, so I can not go with Solr. Also, I cannot use the native full-text support in mysql, since currently my site database uses the InnoDB mechanism.

+4
source share
1 answer

Consider manually building an inverted index in the MyISAM table. The hard part will be to keep the index up to date, although it will require a lot of code when updating / inserting rows or require a full reindexing every x days (or hours).

If you do not know what an inverted index is: this is the index in which you match the word with the document identifier. For example, if you want to index the table (id, name, description) using (1, "Test product", "This product is awesome"), you can divide the words into "Test", "product", "This" "is "," awesome. " Then you can put all these words in the database table (id, word, docID) => (1, "test", 1), (2, "product", 1), (3, "This", 1) and other

If you want to look for something, ask this index. The search query "test" will pull all records with the word = "test", which will be (1, "test", 1). Then he knows that he needs docID 1, and everything is ready.

This is definitely more complicated than using a standard solution, but it should work for your situation :)

Of course, it only works with languages ​​separated by spaces. If you want Chinese, you will have a problem.

[edit] Ah yes, a Wikipedia entry can help: http://en.wikipedia.org/wiki/Inverted_index

+3
source

Source: https://habr.com/ru/post/1383185/


All Articles