add channel keyword search

This commit is contained in:
simon 2022-07-20 14:48:41 +07:00
parent 0a2b6ee90a
commit ae3cf7eb80
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
1 changed files with 32 additions and 0 deletions

View File

@ -300,6 +300,7 @@ class QueryBuilder:
exec_map = {
"video": self._build_video,
"channel": self._build_channel,
}
build_must_list = exec_map[self.query_type]
@ -350,3 +351,34 @@ class QueryBuilder:
)
return must_list
def _build_channel(self):
"""build query for channel"""
must_list = []
if (term := self.query_map.get("term")) is not None:
must_list.append(
{
"multi_match": {
"query": term,
"type": "bool_prefix",
"fuzziness": "auto",
"fields": [
"channel_description",
"channel_name._2gram",
"channel_name._3gram",
"channel_name.search_as_you_type",
],
}
}
)
if (active := self.query_map.get("active")) is not None:
must_list.append({"term": {"channel_active": {"value": active}}})
if (active := self.query_map.get("subscribed")) is not None:
must_list.append(
{"term": {"channel_subscribed": {"value": active}}}
)
return must_list