Skip to content

Instantly share code, notes, and snippets.

@davidmcclure
Created March 4, 2020 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidmcclure/d4025db59f70b76151e36d68765b8775 to your computer and use it in GitHub Desktop.
Save davidmcclure/d4025db59f70b76151e36d68765b8775 to your computer and use it in GitHub Desktop.
class Field(PointIndex):
fields = {
'title': {
'type': 'text',
'term_vector': 'with_positions_offsets',
},
'description': {
'type': 'text',
'term_vector': 'with_positions_offsets',
},
'description_short': {
'type': 'text',
'index': False,
},
'color': {
'type': 'float',
'index': False,
},
}
def search_query(self, qs):
return {
'bool': {
'should': [
# Word-level matches, cross-field.
{'multi_match': {
'query': qs,
'fields': ['title', 'description'],
'type': 'cross_fields',
'operator': 'and',
}},
# Phrase prefix matches.
{'multi_match': {
'query': qs,
'fields': ['title', 'description'],
'type': 'phrase_prefix',
}},
]
}
}
highlight = {
'type': 'fvh',
'fields': {
'title': {
# Always take full title, effectively.
'fragment_size': 1000,
'number_of_fragments': 1,
},
'description': {
'fragment_size': 200,
'number_of_fragments': 2,
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment