-
Notifications
You must be signed in to change notification settings - Fork 0
/
queries.py
97 lines (90 loc) · 2.75 KB
/
queries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def single_phrase_prefix_match(query, field):
q = {
"size": 200,
"explain": True,
"query": {
"match_phrase_prefix": {
field: {
"query": query,
"analyzer": "standard",
# standard, simple, whitespace, stop, keyword, pattern, <language>, fingerprint
}
}
},
"aggs": {
"Poet Filter": {
"terms": {
"field": "Poet_English_Name.keyword",
"size": 10
}
},
"Year Filter": {
"terms": {
"field": "Year.keyword",
"size": 10
}
}
}
}
return q
def exact_field_match(query, field):
q = {
"query": {
"term": {
field: query
}
},
"aggs": {
"Poet Filter": {
"terms": {
"field": "Poet_English_Name.keyword",
"size": 10
}
},
"Year Filter": {
"terms": {
"field": "Year.keyword",
"size": 10
}
}
}
}
return q
def fuzzy_multi_match(query, fields, operator='or'):
q = {
"size": 200,
"explain": True,
"query": {
"multi_match": {
"query": query,
"fields": fields,
"type": "best_fields", # best_fields, most_fields, cross-fields, phrase, phrase_prefix try all
"operator": operator,
# "minimum_should_match": 2, # How many terms must be included to match if the operator is or
"analyzer": "standard", # standard, simple, whitespace, stop, keyword, pattern, <language>, fingerprint
"fuzziness": "AUTO",
# The number of character edits (insert, delete, substitute) to get the required term
"fuzzy_transpositions": True, # Allow character swaps
"lenient": False, # Avoid data type similarity requirement
"prefix_length": 0,
"max_expansions": 50,
"auto_generate_synonyms_phrase_query": True,
"zero_terms_query": "none"
}
},
"aggs": {
"Poet Filter": {
"terms": {
"field": "Poet_English_Name.keyword",
"size": 10
}
},
"Year Filter": {
"terms": {
"field": "Year.keyword",
"size": 10
}
}
}
}
return q