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.
- {esentity-0.2.301 → esentity-0.2.303}/PKG-INFO +1 -1
- esentity-0.2.303/esentity/__init__.py +1 -0
- {esentity-0.2.301 → esentity-0.2.303}/esentity/api.py +3 -2
- {esentity-0.2.301 → esentity-0.2.303}/esentity/models.py +69 -47
- {esentity-0.2.301 → esentity-0.2.303}/pyproject.toml +1 -1
- {esentity-0.2.301 → esentity-0.2.303}/setup.py +1 -1
- esentity-0.2.301/esentity/__init__.py +0 -1
- {esentity-0.2.301 → esentity-0.2.303}/esentity/encoder.py +0 -0
- {esentity-0.2.301 → esentity-0.2.303}/esentity/ext.py +0 -0
- {esentity-0.2.301 → esentity-0.2.303}/esentity/filters.py +0 -0
- {esentity-0.2.301 → esentity-0.2.303}/esentity/routes.py +0 -0
- {esentity-0.2.301 → esentity-0.2.303}/esentity/tasks.py +0 -0
- {esentity-0.2.301 → esentity-0.2.303}/esentity/telegram.py +0 -0
|
@@ -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
|
-
|
|
1129
|
-
|
|
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,
|
|
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
|
-
|
|
974
|
-
|
|
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
|
-
|
|
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":
|
|
988
|
+
"query": query_string,
|
|
996
989
|
"fields": [
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
"
|
|
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
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
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
|
-
|
|
1056
|
-
|
|
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
|
|
1090
|
+
return url_for('visit', alias=self.external_id or self.alias)
|
|
1069
1091
|
|
|
1070
1092
|
@property
|
|
1071
1093
|
def acceptable(self):
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = '0.2.301'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|