Changes
Page history
Create Suggestions ("Did you mean" feature!)
authored
Jun 25, 2022
by
Fruth, Leon
Show whitespace changes
Inline
Side-by-side
Suggestions-("Did-you-mean"-feature!).md
0 → 100644
View page @
fd731dff
[
Elasticsearch Documentation
](
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html
)
-
Term suggester: Suggests corrections for individual terms in a search string:
-
Phrase suggester: Suggests corrections for phrases.
## Phrase suggester
1.
Works with phrases:
Query:
```
json
{
"suggest"
:
{
"text"
:
"data minding"
,
"phrase_suggest"
:
{
"phrase"
:
{
"field"
:
"_content.Page.Content.Body.~"
}}
}
}
```
Results:
```
json
"suggest"
:
{
"phrase_suggest"
:
[
{
"text"
:
"data minding"
,
"offset"
:
0
,
"length"
:
12
,
"options"
:
[
{
"text"
:
"data mining"
,
"score"
:
0.002154175
},
{
"text"
:
"data missing"
,
"score"
:
0.0012882735
},
{
"text"
:
"data manning"
,
"score"
:
0.0010319541
}
]
}
]
}
```
2.
Works with individual terms too
Query:
```
json
{
"suggest"
:
{
"text"
:
"pyhton"
,
"phrase_suggest"
:
{
"phrase"
:
{
"field"
:
"_content.Page.Content.Body.~"
}}
}
}
```
Results:
```
json
"suggest"
:
{
"phrase_suggest"
:
[
{
"text"
:
"pyhton"
,
"offset"
:
0
,
"length"
:
6
,
"options"
:
[
{
"text"
:
"python"
,
"score"
:
0.06817966
}
]
}
]
}
```
### How does it work
### Settings and Arguments
## Building a "Did you mean"-Feature
### Idea:
1.
Using the phrase suggester on the title field and the body field
2.
Aggregating the results
3.
Return top result
### Examples:
#### Search string: **"Pahton"**
1.
Suggestions
-
Title Field: []
-
Body Field: [{'text': 'python', 'score': 0.061882425}, {'text': 'pyhton', 'score': 0.020105202}]
2.
Aggregated results: [{'text': 'python', 'score': 0.061882425}, {'text': 'pyhton', 'score': 0.020105202}]
3.
**Did you mean: "python"**
#### Search string: **"data midning"**
1.
Suggestions
-
Title Field: [{'text': 'data mining', 'score': 0.012581152}]
-
Body Field: [{'text': 'data mining', 'score': 0.002154175}, {'text': 'data missing', 'score': 0.0012882735}, {'text': 'data manning', 'score': 0.0010319541}, {'text': 'data meaning', 'score': 0.0010319541}]
2.
Aggregated results: [{'text': 'data mining', 'score': 0.014735327}, {'text': 'data missing', 'score': 0.0012882735}, {'text': 'data manning', 'score': 0.0010319541}, {'text': 'data meaning', 'score': 0.0010319541}]
3.
**Did you mean: "data mining"**
#### Search string: **"data midning"**
1.
Suggestions
-
Title Field: [{'text': 'data mining', 'score': 0.012581152}]
-
Body Field: [{'text': 'data mining', 'score': 0.002154175}, {'text': 'data missing', 'score': 0.0012882735}, {'text': 'data manning', 'score': 0.0010319541}, {'text': 'data meaning', 'score': 0.0010319541}]
2.
Aggregated results: [{'text': 'data mining', 'score': 0.014735327}, {'text': 'data missing', 'score': 0.0012882735}, {'text': 'data manning', 'score': 0.0010319541}, {'text': 'data meaning', 'score': 0.0010319541}]