Created
September 15, 2020 06:10
-
-
Save boutros/6f3590ecf54ba3ed6ed70da865b327f2 to your computer and use it in GitHub Desktop.
terms query boost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/sibyl/assets/esconf/autocomplete_mapping.json b/sibyl/assets/esconf/autocomplete_mapping.json | |
index b98efeb73..ff10abd7b 100644 | |
--- a/sibyl/assets/esconf/autocomplete_mapping.json | |
+++ b/sibyl/assets/esconf/autocomplete_mapping.json | |
@@ -5,6 +5,9 @@ | |
"analyzer": "autocomplete", | |
"search_analyzer": "autocomplete_search" | |
}, | |
+ "exact": { | |
+ "type": "keyword" | |
+ }, | |
"gain": { | |
"type": "float" | |
}, | |
diff --git a/sibyl/internal/admin/index/acbuilder.go b/sibyl/internal/admin/index/acbuilder.go | |
index 31bebb8b4..73f4d1077 100644 | |
--- a/sibyl/internal/admin/index/acbuilder.go | |
+++ b/sibyl/internal/admin/index/acbuilder.go | |
@@ -197,11 +197,11 @@ func (ia *IndexAdmin) buildAutocompleteIndex() { | |
var b bytes.Buffer | |
const bulkSize = 1000 | |
const docTmpl = `{"index": {"_index": "autocomplete", "_id":%q } } | |
-{"entry":%q,"gain":1.0,"type":"%s", "id":%q} | |
+{"entry":%q,"exact":%q,"gain":1.0,"type":"%s", "id":%q} | |
` | |
i := 0 | |
for id, e := range entries { | |
- b.WriteString(fmt.Sprintf(docTmpl, id, e.Entry, e.Type, e.ID)) | |
+ b.WriteString(fmt.Sprintf(docTmpl, id, e.Entry, e.Entry, e.Type, e.ID)) | |
i++ | |
if i == bulkSize || i == len(entries)-1 { | |
req, err := http.NewRequest(http.MethodPost, elastic+"/_bulk", &b) | |
diff --git a/sibyl/internal/search/autocomplete/autocomplete.go b/sibyl/internal/search/autocomplete/autocomplete.go | |
index 1df96f0b3..7c0153811 100644 | |
--- a/sibyl/internal/search/autocomplete/autocomplete.go | |
+++ b/sibyl/internal/search/autocomplete/autocomplete.go | |
@@ -50,15 +50,23 @@ func (c Client) Search(q string, size int, fuzziness bool) ([]hitDoc, error) { | |
matchQ := elastic.NewMultiMatchQuery(q, "entry", "entry._2gram", "entry._3gram"). | |
Type("bool_prefix"). | |
- MinimumShouldMatch("2<75%") | |
+ MinimumShouldMatch("2<75%"). | |
+ Boost(1) | |
if fuzziness { | |
matchQ = matchQ.Fuzziness("AUTO") | |
} | |
- query := elastic.NewFunctionScoreQuery(). | |
+ matchQExact := elastic.NewTermQuery("exact.keyword", q). | |
+ Boost(100) | |
+ | |
+ query := elastic.NewBoolQuery().Should(matchQExact, matchQ) | |
+ | |
+ /* | |
+ query := elastic.NewFunctionScoreQuery(). | |
Query(matchQ). | |
AddScoreFunc(elastic.NewFieldValueFactorFunction().Factor(2).Field("gain")) | |
+ */ | |
fetchContext := elastic.NewFetchSourceContext(true).Include("entry", "type", "id") | |
search := c.esClient. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment