Skip to content

Commit

Permalink
Fix search pagination with Manticore 6.3.0 (and make some small impro…
Browse files Browse the repository at this point in the history
…vements)
  • Loading branch information
andreymal committed Jun 8, 2024
1 parent 7bac53f commit 0ce532f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
8 changes: 6 additions & 2 deletions mini_fiction/apis/amsphinxql.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def escape_match(cls, s: str) -> str:

return s

def build_search_sql(
def _build_search_sql(
self,
index: str,
query: str,
Expand Down Expand Up @@ -226,7 +226,10 @@ def search(
) -> SphinxSearchResult:
from MySQLdb import ProgrammingError

sql, args = self.build_search_sql(
options = dict(options) or {}
options.setdefault("max_matches", 1000)

sql, args = self._build_search_sql(
index, query, fields, raw_fields, sort_by, limit, options, weights, extended_syntax, **filters
)

Expand All @@ -244,6 +247,7 @@ def search(
if meta:
cur.execute("show meta")
meta_result = dict(cur.fetchall())
meta_result["max_matches"] = int(options["max_matches"])

result = SphinxSearchResult(
matches=matches,
Expand Down
16 changes: 12 additions & 4 deletions mini_fiction/bl/stories.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,12 +1031,16 @@ def search(
stories = [stories_dict[i] for i in ids if i in stories_dict]
enrich_stories(stories)

max_matches = int(result_orig.meta["max_matches"])
total_found = int(result_orig.meta["total_found"])
total = min(max_matches, total_found)

return StorySearchResult(
matches=result_orig.matches,
meta=result_orig.meta,
sql=result_orig.sql,
total=int(result_orig.meta["total"]),
total_found=int(result_orig.meta["total_found"]),
total=total,
total_found=total_found,
stories=stories,
)

Expand Down Expand Up @@ -2292,11 +2296,15 @@ def search(
)
chapters.append((chapters_dict[i], excerpt[0] if excerpt else ""))

max_matches = int(result_orig.meta["max_matches"])
total_found = int(result_orig.meta["total_found"])
total = min(max_matches, total_found)

return ChapterSearchResult(
matches=result_orig.matches,
meta=result_orig.meta,
sql=result_orig.sql,
total=int(result_orig.meta["total"]),
total_found=int(result_orig.meta["total_found"]),
total=total,
total_found=total_found,
chapters=chapters,
)
6 changes: 3 additions & 3 deletions mini_fiction/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,18 @@ class Config(object):
SPHINX_ROOT = os.path.join(os.getcwd(), 'sphinx')
SPHINX_CONFIG = {
'connection_params': {'unix_socket': '/tmp/sphinx_fanfics.socket', 'charset': 'utf8mb4'},
'excerpts_opts': {'chunk_separator': '…', 'limit': 2048, 'around': 10, 'html_strip_mode': 'strip'},
'excerpts_opts': {'chunk_separator': '…', 'limit': 2048, 'around': 20, 'html_strip_mode': 'strip'},

'stories_rt_mem_limit': '128M',
'chapters_rt_mem_limit': '256M',

'weights_stories': {'title': 100, 'summary': 50, 'notes': 25, 'username': 150},
'weights_chapters': {'text': 100, 'title': 50, 'notes': 25},

'limit': 10,
'limit': 20,
'select_options': {
'ranker': 'sph04',
'max_matches': 1000,
'max_matches': 5000,
'retry_count': 5,
'retry_delay': 1,
'max_query_time': 10000, # in milliseconds
Expand Down

0 comments on commit 0ce532f

Please sign in to comment.