Skip to content

Commit

Permalink
added an artificial snippet [Synonym Match] in case that there is onl…
Browse files Browse the repository at this point in the history
…y a match in the synonyms]
  • Loading branch information
Orbiter committed Sep 21, 2024
1 parent f57df06 commit a8c64b1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions source/net/yacy/kelondro/data/meta/URIMetadataNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,10 @@ public String[] collections() {
public WordReferenceVars word() {
return this.word;
}

public ArrayList<String> getSynonyms() {
return getStringList(CollectionSchema.synonyms_sxt);
}

public static Iterator<String> getLinks(SolrDocument doc, boolean inbound) {
Collection<Object> urlstub = doc.getFieldValues((inbound ? CollectionSchema.inboundlinks_urlstub_sxt : CollectionSchema.outboundlinks_urlstub_sxt).getSolrFieldName());
Expand Down
15 changes: 15 additions & 0 deletions source/net/yacy/search/query/SearchEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -2056,6 +2056,21 @@ public URIMetadataNode getSnippet(URIMetadataNode page, final CacheStrategy cach
if (this.deleteIfSnippetFail) {
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);
return null;
}
Expand Down

0 comments on commit a8c64b1

Please sign in to comment.