added an artificial snippet [Synonym Match] in case that there is only a match in the synonyms]

master
Michael Peter Christen 2 months ago
parent f57df061da
commit a8c64b1af2

@ -516,6 +516,10 @@ public class URIMetadataNode extends SolrDocument /* implements Comparable<URIMe
public WordReferenceVars word() { public WordReferenceVars word() {
return this.word; return this.word;
} }
public ArrayList<String> getSynonyms() {
return getStringList(CollectionSchema.synonyms_sxt);
}
public static Iterator<String> getLinks(SolrDocument doc, boolean inbound) { public static Iterator<String> getLinks(SolrDocument doc, boolean inbound) {
Collection<Object> urlstub = doc.getFieldValues((inbound ? CollectionSchema.inboundlinks_urlstub_sxt : CollectionSchema.outboundlinks_urlstub_sxt).getSolrFieldName()); Collection<Object> urlstub = doc.getFieldValues((inbound ? CollectionSchema.inboundlinks_urlstub_sxt : CollectionSchema.outboundlinks_urlstub_sxt).getSolrFieldName());

@ -2056,6 +2056,21 @@ public final class SearchEvent implements ScoreMapUpdatesListener {
if (this.deleteIfSnippetFail) { if (this.deleteIfSnippetFail) {
this.workTables.failURLsRegisterMissingWord(this.query.getSegment().termIndex(), page.url(), this.query.getQueryGoal().getIncludeHashes()); this.workTables.failURLsRegisterMissingWord(this.query.getSegment().termIndex(), page.url(), this.query.getQueryGoal().getIncludeHashes());
} }
// to make an exception in case matches are only in the synonym field, we load the synonym field to check if the word is there
final ArrayList<String> synonyms = page.getSynonyms();
if (synonyms != null) {
Iterator<String> words = this.query.getQueryGoal().getIncludeWords();
while (words.hasNext()) {
String word = words.next().toLowerCase();
for (final String synonym : synonyms) {
if (synonym.toLowerCase().equals(word)) {
SearchEvent.log.info("accepted url " + page.url().toNormalform(true) + " without snippet: hit in synonyms field");
TextSnippet synonym_snippet = new TextSnippet(page.url(), "[Synonym Match]", true, ResultClass.SOURCE_METADATA, "");
return page.makeResultEntry(this.query.getSegment(), this.peers, synonym_snippet);
}
}
}
}
SearchEvent.log.info("sorted out url " + page.url().toNormalform(true) + " during search: " + reason); SearchEvent.log.info("sorted out url " + page.url().toNormalform(true) + " during search: " + reason);
return null; return null;
} }

Loading…
Cancel
Save