Hi!
My search engine uses the following function to calculate relevancy.
private static int calculateScore(String result, String searchStr, int modifier)
{
String[] resultWords = result.split(" ");
String[] searchWords = searchStr.split(" ");
int score = 0;
for (String searchWord : searchWords)
{
for (String resultWord : resultWords)
{
if (resultWord.equals(searchWord))
score += 10;
else if (resultWord.startsWith(searchWord))
score += 4;
else if (resultWord.endsWith(searchWord))
score += 3;
else if (resultWord.contains(searchWord))
score += 1;
}
}
return score;
}
Nothing fancy, and I haven't been given enough hours to do anything fancy either, but are there any simple improvements I can do to make the function better at upping the relevant stuff, and keeping the irrelevant stuff down? No need to remark on speed optimizations, this is just the "functional part" of the function :)
Thanks.