This commit is contained in:
parent
306caf9520
commit
5fe51e03bb
|
@ -1,4 +1,4 @@
|
||||||
from sqlalchemy import and_, distinct, func, join, select
|
from sqlalchemy import and_, distinct, func, join, select, CompoundSelect
|
||||||
from sqlalchemy.orm import aliased
|
from sqlalchemy.orm import aliased
|
||||||
|
|
||||||
from orm.author import Author, AuthorFollower
|
from orm.author import Author, AuthorFollower
|
||||||
|
@ -180,16 +180,17 @@ def get_author_comments_stat(author_id: int):
|
||||||
def get_with_stat(q):
|
def get_with_stat(q):
|
||||||
records = []
|
records = []
|
||||||
try:
|
try:
|
||||||
is_author = f"{q}".lower().startswith("select author")
|
|
||||||
# is_topic = f"{q}".lower().startswith("select topic")
|
|
||||||
result = []
|
|
||||||
if is_author:
|
|
||||||
q = add_author_stat_columns(q)
|
|
||||||
else:
|
|
||||||
q = add_topic_stat_columns(q)
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
result = session.execute(q)
|
# Convert the CompoundSelect object to a Query object
|
||||||
|
if isinstance(q, CompoundSelect):
|
||||||
|
q = session.query().from_statement(q)
|
||||||
|
|
||||||
|
# detect author
|
||||||
|
is_author = f"{q}".lower().startswith("select author")
|
||||||
|
q = add_author_stat_columns(q) if is_author else add_topic_stat_columns(q)
|
||||||
|
|
||||||
|
# execute query
|
||||||
|
result = session.execute(q)
|
||||||
for cols in result:
|
for cols in result:
|
||||||
entity = cols[0]
|
entity = cols[0]
|
||||||
stat = dict()
|
stat = dict()
|
||||||
|
|
|
@ -138,13 +138,17 @@ class SearchService:
|
||||||
result = json.loads(result)
|
result = json.loads(result)
|
||||||
if isinstance(result, dict):
|
if isinstance(result, dict):
|
||||||
mapping = result.get(self.index_name, {}).get("mappings")
|
mapping = result.get(self.index_name, {}).get("mappings")
|
||||||
logger.debug(f"Найдена структура индексации: {mapping['properties'].keys()}")
|
logger.debug(
|
||||||
|
f"Найдена структура индексации: {mapping['properties'].keys()}"
|
||||||
|
)
|
||||||
if (
|
if (
|
||||||
mapping
|
mapping
|
||||||
and mapping["properties"].keys()
|
and mapping["properties"].keys()
|
||||||
!= expected_mapping["properties"].keys()
|
!= expected_mapping["properties"].keys()
|
||||||
):
|
):
|
||||||
logger.debug(f"Ожидаемая структура индексации: {expected_mapping}")
|
logger.debug(
|
||||||
|
f"Ожидаемая структура индексации: {expected_mapping}"
|
||||||
|
)
|
||||||
logger.warn("[!!!] Требуется переиндексация всех данных")
|
logger.warn("[!!!] Требуется переиндексация всех данных")
|
||||||
self.delete_index()
|
self.delete_index()
|
||||||
self.client = None
|
self.client = None
|
||||||
|
|
Loading…
Reference in New Issue
Block a user