I wrote a search engine recently.... and you have to think not about coding it, but about logic.
HOW does it get compared?
Think about google. You know they're not just doing it word for word. They find words, then compare for relevance, narrow down the lists, then compare for context and words in more important contexts would be more relevant for searching... it also ignores words like the, of, etc.
Not looking at your code, exactly, I'm not too sure how it works, but I can explain what I did, and that it works:
--For every result, I made a name, description, link, set of keywords, catergory, etc.
--If the input matched the keywords, the name, description and link would appear. (The name was also used as a variable name...
PHP Code:
$keywords = $name$keywords
$$keywords = "keyword other stuff blah blah blah"
so that you could have relatively named keywords, descriptions, etc.)
--NOTE: I DIDN'T use a database, just a php file with the above code in it. I plan to make a database now, to make it easier to modify. The same logic should apply, though.
Ok... so now that you get how this works... I can explain how I did keywords:
As you saw above, my keywords were seperated by spaces. That's it.
When checking, it got the keywords as a variable, then went through character by character, until it hit a space. It saved the letters before the space in another variable, $keyword.
Then it checked if any of the $term variables (seperated EXACTLY the same way) matched it.
Then it did so for the next keyword, finding the next space, etc.
I also added things like ignoring words like the, of, etc. (in the input... the keywords wouldn't have these... I wouldn't input them.)
and sorting results by relevance. I added another variable named variable, $$matches (see above for how) and added 1 to that each time an input term matched a keyword. At the end, it would compare the number of words (remember to store this as a variable at the beginning) to the number of matches for each possible result:
0 would mean no result... it wouldn't do anything.
if $numofwords = $$matches, then it would be a complete result. If not,
it would be a partial result, and displayed under that heading. Also, it goes through and ranks them for how MUCH less they are than full... giving your results that all but 1 of your terms match, then all but 2, etc. so that the more relevant ones are on top.
Now, if you want to see this in action, visit:
http://thebrb.com/stockpile/search.php
Try searching for stuff related to filmmaking, as that's what the site is about. You'll see how it works.
If you want, talk to me on AIM.
I'm d33jr.
I'm working on this too, so maybe we could help each other out a bit.
Bookmarks