Created
March 4, 2020 14:33
-
-
Save davidmcclure/d4025db59f70b76151e36d68765b8775 to your computer and use it in GitHub Desktop.
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
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