esentity 0.2.301__tar.gz → 0.2.303__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: esentity
3
- Version: 0.2.301
3
+ Version: 0.2.303
4
4
  Summary: Elasticsearch Entity Tools
5
5
  Home-page: https://slotmarks.com
6
6
  Author: Slotmarks
@@ -0,0 +1 @@
1
+ __version__ = '0.2.303'
@@ -1125,8 +1125,9 @@ class ApiAuthLogin(Resource):
1125
1125
 
1126
1126
  session['actor'] = obj.to_dict()
1127
1127
 
1128
- msg = ':man: Auth success: {0}, IP: {1} [{2}]'.format(obj.username, current_user.ip, current_user.location_iso.upper())
1129
- send_notify.apply_async(args=[msg, 'notify'])
1128
+ if not data.get('silent', False):
1129
+ msg = ':man: Auth success: {0}, IP: {1} [{2}]'.format(obj.username, current_user.ip, current_user.location_iso.upper())
1130
+ send_notify.apply_async(args=[msg, 'notify'])
1130
1131
 
1131
1132
  return {'ok': True, 'user': obj.to_dict()}
1132
1133
  else:
@@ -964,45 +964,36 @@ class Page(ElasticEntity):
964
964
  return None
965
965
 
966
966
  @classmethod
967
- def query(cls, query, is_full=False, locale_list=[], category=[], page=1, count=10, match_type='bool_prefix'):
968
- if not query:
969
- return []
967
+ def query(cls, query, is_full=False, _locale=[], category=[], page=1, count=10):
968
+ if not query or not str(query).strip():
969
+ return
970
970
 
971
971
  def escape_query_string(text):
972
972
  # Экранируем спецсимволы Lucene: + - = && || > < ! ( ) { } [ ] ^ " ~ * ? : \ /
973
- # return re.sub(r'([+\-=&|><!(){}\[\]^"~*?:\\/])', r'\\\1', text)
974
- return text.replace('-', ' ')
973
+ return re.sub(r'([+\-=&|><!(){}\[\]^"~*?:\\/])', lambda m: '\\' + m.group(1), text)
974
+
975
+ query_str = str(query).strip().replace('-', ' ')
976
+ raw_words = query_str.split()
977
+ clean_words = [escape_query_string(w) for w in raw_words if escape_query_string(w)]
978
+
979
+ if not clean_words:
980
+ return
975
981
 
976
- query = ' AND '.join([f'*{escape_query_string(item)}*' for item in query.split()])
982
+ query_parts = [f'({w}^20 OR {w}*^10 OR *{w}*)' for w in clean_words]
983
+ query_string = ' AND '.join(query_parts)
977
984
 
978
985
  must = [
979
- # {"multi_match" : {
980
- # "query": query,
981
- # "type": match_type,
982
- # "fields": [
983
- # "suggest",
984
- # "suggest._2gram",
985
- # "suggest._3gram",
986
- # "title^3",
987
- # "alias",
988
- # "intro^2",
989
- # "overview",
990
- # "content",
991
- # ]
992
- # }}
993
986
  {
994
987
  "query_string": {
995
- "query": query,
988
+ "query": query_string,
996
989
  "fields": [
997
- # "suggest",
998
- # "suggest._2gram",
999
- # "suggest._3gram",
1000
- "title^3",
1001
- "alias",
990
+ "title^10",
991
+ "alias^8",
992
+ "website^5",
993
+ "suggest^4",
1002
994
  "intro^2",
1003
- "overview",
1004
- "content",
1005
- "website",
995
+ # "overview^1",
996
+ # "content^0.5",
1006
997
  ]
1007
998
  }
1008
999
  }
@@ -1018,20 +1009,44 @@ class Page(ElasticEntity):
1018
1009
  if category:
1019
1010
  must.append({"terms": {"category.keyword": category}})
1020
1011
 
1021
- # TODO: search slots and casinos ???
1022
- # if current_app.config.get('ENTITY_MULTIPLE_LOCALE', False):
1023
- # params['locale_available'] = _locale or g.language
1024
- # _locale = None
1025
- # else:
1026
- # _locale = _locale or g.language
1027
-
1028
- if locale_list:
1029
- must.append({"terms": {"locale.keyword": locale_list}})
1030
- # elif al := current_app.config.get('AVAILABLE_LOCALE'):
1031
- # must.append({"terms": {"locale.keyword": al}})
1032
-
1033
- # if in_locale:
1034
- # must.append({"term": {"locale_available.keyword": in_locale}})
1012
+ if _locale:
1013
+ locales = [_locale] if isinstance(_locale, str) else list(_locale)
1014
+ if locales:
1015
+ must.append({
1016
+ "bool": {
1017
+ "should": [
1018
+ {
1019
+ "bool": {
1020
+ "must": [
1021
+ {"terms": {"category.keyword": ["page", "collection"]}},
1022
+ {"terms": {"locale.keyword": locales}}
1023
+ ]
1024
+ }
1025
+ },
1026
+ {
1027
+ "bool": {
1028
+ "must": [
1029
+ {"terms": {"category.keyword": ["provider", "slot"]}},
1030
+ {"terms": {"locale_available.keyword": locales}}
1031
+ ]
1032
+ }
1033
+ },
1034
+ {
1035
+ "bool": {
1036
+ "must_not": [
1037
+ {"terms": {"category.keyword": ["page", "collection", "provider", "slot"]}}
1038
+ ],
1039
+ "should": [
1040
+ {"terms": {"locale.keyword": locales}},
1041
+ {"terms": {"locale_available.keyword": locales}}
1042
+ ],
1043
+ "minimum_should_match": 1
1044
+ }
1045
+ }
1046
+ ],
1047
+ "minimum_should_match": 1
1048
+ }
1049
+ })
1035
1050
 
1036
1051
  q = {
1037
1052
  "query": {
@@ -1052,11 +1067,18 @@ class Page(ElasticEntity):
1052
1067
  }
1053
1068
 
1054
1069
  logger.debug(f'Search query: {q}')
1055
- resp = current_app.es.search(index=cls._table(), body=q, request_timeout=60, ignore=[404])
1056
- logger.debug(f'Search query response: {resp}')
1070
+ try:
1071
+ resp = current_app.es.search(index=cls._table(), body=q, request_timeout=60, ignore=[400, 404])
1072
+ except Exception as e:
1073
+ logger.warning(f'Elasticsearch search error: {e}')
1074
+ return
1075
+
1076
+ if not resp or 'hits' not in resp or 'hits' not in resp['hits']:
1077
+ logger.warning(f'Search query returned invalid response: {resp}')
1078
+ return
1057
1079
 
1058
1080
  if 'status' in resp and resp['status'] in [400, 404]:
1059
- return []
1081
+ return
1060
1082
 
1061
1083
  for item in resp['hits']['hits']:
1062
1084
  obj = cls(item['_source'], item['_id'])
@@ -1065,7 +1087,7 @@ class Page(ElasticEntity):
1065
1087
 
1066
1088
  @property
1067
1089
  def visit_url(self):
1068
- return u_func('visit', alias=self.external_id or self.alias)
1090
+ return url_for('visit', alias=self.external_id or self.alias)
1069
1091
 
1070
1092
  @property
1071
1093
  def acceptable(self):
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "esentity"
3
- version = "0.2.301"
3
+ version = "0.2.303"
4
4
  description = "Elasticsearch Entity Tools"
5
5
  authors = ["Slotmarks <info@slotmarks.com>"]
6
6
  homepage = "https://slotmarks.com"
@@ -9,7 +9,7 @@ package_data = \
9
9
 
10
10
  setup_kwargs = {
11
11
  'name': 'esentity',
12
- 'version': '0.2.301',
12
+ 'version': '0.2.303',
13
13
  'description': 'Elasticsearch Entity Tools',
14
14
  'long_description': None,
15
15
  'author': 'Slotmarks',
@@ -1 +0,0 @@
1
- __version__ = '0.2.301'
File without changes
File without changes