First of all:
– I can’t use sphinx because i use share hosting
– I don’t like google solutions ie. custom search have these stupid ad and site search isn’t free
I want to create search mechanizm on my own. I have pages table and i want to search pages content by keywords and on result page i want to show part of text which is matched with desired keywords (same like google does).
Thx in advanced
Then you have two ( and a half ) choices:
Here is short version of how you can do the 2nd option:
Lets say you want to search the content of your articles.
Basically what you have to to is create an index of all the words you might want to search for.
Code below taken from book SQL Antipatterns and modified only tiny bit.
I will assume that you want to index articles:
You need a table for keywords ( each keyword can be in multiple articles ):
Now the table to implement many-to-many relationship:
And next you create a stored procedure, which populates your indexing mechanism:
Now you can use this procedure to search the index for keyword.
CALL ArticlesSearch('OMG');The last part of solution is making sure that each new articles is automatically indexed:
.
P.S. i have never needed to test this approach, that’s why i cannot guarantee that it will work.