Skip to content

Commit

Permalink
Detect if index supports spell checking (#1461)
Browse files Browse the repository at this point in the history
  • Loading branch information
olovy authored Aug 2, 2024
1 parent 4d16a7b commit cf9ce06
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions whelk-core/src/main/groovy/whelk/search/ESQuery.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class ESQuery {
private Map<String, List<String>> boostFieldsByType = [:]
private ESQueryLensBoost lensBoost

// TODO: temporary feature flag, to be removed
// this feature only works after a full reindex has been done, so we have to detect that
private boolean ENABLE_SPELL_CHECK = false

ESQuery() {
// NOTE: For unit tests only!
}
Expand All @@ -86,6 +90,11 @@ class ESQuery {
this.nestedFields = getFieldsOfType('nested', mappings)
this.nestedNotInParentFields = nestedFields - getFieldsWithSetting('include_in_parent', true, mappings)
this.numericExtractorFields = getFieldsWithAnalyzer('numeric_extractor', mappings)

if (DocumentUtil.getAtPath(mappings, ['properties', '_sortKeyByLang', 'properties', 'sv', 'fields', 'trigram'], null)) {
ENABLE_SPELL_CHECK = true
}
log.info("ENABLE_SPELL_CHECK = ${ENABLE_SPELL_CHECK}")
} else {
this.keywordFields = Collections.emptySet()
this.dateFields = Collections.emptySet()
Expand Down Expand Up @@ -165,7 +174,7 @@ class ESQuery {
}
// If the `_spell` query param is "only", return a query containing *only*
// the spell checking part
if (spell == "only" && q) {
if (ENABLE_SPELL_CHECK && spell == "only" && q) {
return ['suggest': spellQuery]
}

Expand Down Expand Up @@ -306,7 +315,7 @@ class ESQuery {
query['post_filter'] = ['bool': ['must' : multiSelectFilters.values()]]
}

if (spell && q) {
if (ENABLE_SPELL_CHECK && spell && q) {
query['suggest'] = spellQuery
}

Expand Down

0 comments on commit cf9ce06

Please sign in to comment.