Skip to content

Commit

Permalink
TRUNK-4375 Follow up changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rkorytkowski committed Jun 23, 2014
1 parent b17c387 commit 8f78354
Showing 1 changed file with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -617,15 +617,19 @@ private String newNamesQuery(final Set<Locale> locales, final String name, final
if (keywords) {
List<String> words = tokenizeName(escapedName, locales);

query.append(" name:(" + StringUtils.join(words, " ") + ")^0.2");
//Put exact phrase higher
query.append(" OR name:(\"" + escapedName + "\")^0.6");
query.append(" name:(\"" + escapedName + "\")^0.6");

//Include partial
query.append(" OR name:(" + StringUtils.join(words, "* ") + "*)^0.1");

//Include similar
query.append(" OR name:(" + StringUtils.join(words, "~0.8 ") + "~0.8)^0.1");
if (!words.isEmpty()) {
//Include exact
query.append(" OR name:(" + StringUtils.join(words, " ") + ")^0.2");

//Include partial
query.append(" OR name:(" + StringUtils.join(words, "* ") + "*)^0.1");

//Include similar
query.append(" OR name:(" + StringUtils.join(words, "~0.8 ") + "~0.8)^0.1");
}
} else {
query.append(" name:\"" + escapedName + "\"");
}
Expand All @@ -646,24 +650,24 @@ private String newNamesQuery(final Set<Locale> locales, final String name, final

return query.toString();
}

private List<String> tokenizeName(final String escapedName, final Set<Locale> locales) {
List<String> words = new ArrayList<String>();
words.addAll(Arrays.asList(escapedName.trim().split(" ")));
Set<String> stopWords = new HashSet<String>();
for (Locale locale : locales) {
stopWords.addAll(Context.getConceptService().getConceptStopWords(locale));
}
for (Iterator<String> it = words.iterator(); it.hasNext();) {
String word = it.next();
if (stopWords.contains(word.toUpperCase())) {
it.remove();
}
}
return words;
}
List<String> words = new ArrayList<String>();
words.addAll(Arrays.asList(escapedName.trim().split(" ")));
Set<String> stopWords = new HashSet<String>();
for (Locale locale : locales) {
stopWords.addAll(Context.getConceptService().getConceptStopWords(locale));
}
for (Iterator<String> it = words.iterator(); it.hasNext();) {
String word = it.next();
if (stopWords.contains(word.trim().toUpperCase())) {
it.remove();
}
}
return words;
}

/**
* gets questions for the given answer concept
Expand Down

0 comments on commit 8f78354

Please sign in to comment.