Reputation: 608
I want to use search from database on my website, so I think about effective algorithm to use.
For example if I try to search "Hello my name is xxx" I want to see results:
Hello my name is John
Hello my name is Peter
Hello mr. xxx
His name is Peter
He is here
So I want to search all data from database with part of this text and sort result by number of matching words.
I made algorithm but I am pretty scared that it's so complicated and slow:
I split search text into words and use SQL select with multiple like or commands. Then I save this results into list. Then I count up numbers of matched words in each result and sort it by this count.
Problem is that when I will try to search long text.
Should I use better algorithm or should I learn somethink about thinks like Sphinx
Upvotes: 1
Views: 104
Reputation: 4129
For the first two results, a simple regex search should be able to retrieve results like that. For the later ones, you might consider using an existing searching library thing, like Google Search Appliance, which can be used to search database information.
Upvotes: 1