Fetching search estimate with tags separate from suggestions.

This commit is contained in:
Roland 2023-11-26 20:49:36 -07:00
parent ff62f9e21b
commit d87bc7b314
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
9 changed files with 258 additions and 164 deletions

View file

@ -5,6 +5,7 @@ import re
from datetime import datetime
from typing import List, Tuple, Dict
import cachetools.func
from libzim import Entry
from sqlalchemy.orm import Session
from sqlalchemy.orm.exc import NoResultFound # noqa
@ -208,6 +209,13 @@ def headline_zim(search_str: str, zim_id: int, tag_names: List[str] = None, offs
return results
@cachetools.func.mru_cache(maxsize=1_000)
def get_estimates(search_str: str) -> List[int]:
zims = Zims.get_all()
estimates = [i.estimate(search_str) for i in zims]
return estimates
@optional_session
def get_zim(zim_id: int, session: Session = None) -> Zim:
"""Return the Zim record of the provided path.