vomebook commited on
Commit
0dd5a59
·
1 Parent(s): e217eef

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -326,10 +326,14 @@ def metadata_matches(q: str, exact: bool, search_paths: bool) -> set[int]:
326
  if all(term in records[idx][field] for term in terms)
327
  }
328
 
329
- @lru_cache(maxsize=8)
330
- def read_search_text(idx: int) -> str:
331
  file_path = get_doc_storage_path(records[idx])
332
- return file_path.read_text(encoding="utf-8", errors="ignore") if file_path.exists() else ""
 
 
 
 
 
333
 
334
  def verify_fulltext_matches(indices: set[int], query: str) -> set[int]:
335
  return set(cached_verified_fulltext_matches(tuple(sorted(indices)), query))
@@ -338,7 +342,7 @@ def verify_fulltext_matches(indices: set[int], query: str) -> set[int]:
338
  def cached_verified_fulltext_matches(indices: tuple[int, ...], query: str) -> frozenset[int]:
339
  return frozenset(
340
  idx for idx in indices
341
- if matches_exact_query(read_search_text(idx), query)
342
  )
343
 
344
  def search(q="", sources_filter=None, folders=None, min_size=None, max_size=None, page=1, page_size=100, sort="relevance", exact=False, search_paths=True):
 
326
  if all(term in records[idx][field] for term in terms)
327
  }
328
 
329
+ def file_matches_exact_query(idx: int, query: str) -> bool:
 
330
  file_path = get_doc_storage_path(records[idx])
331
+ if not file_path.exists():
332
+ return False
333
+ payload = file_path.read_bytes()
334
+ if "*" not in query and "?" not in query and query.encode("utf-8") in payload:
335
+ return True
336
+ return matches_exact_query(payload.decode("utf-8", errors="ignore"), query)
337
 
338
  def verify_fulltext_matches(indices: set[int], query: str) -> set[int]:
339
  return set(cached_verified_fulltext_matches(tuple(sorted(indices)), query))
 
342
  def cached_verified_fulltext_matches(indices: tuple[int, ...], query: str) -> frozenset[int]:
343
  return frozenset(
344
  idx for idx in indices
345
+ if file_matches_exact_query(idx, query)
346
  )
347
 
348
  def search(q="", sources_filter=None, folders=None, min_size=None, max_size=None, page=1, page_size=100, sort="relevance", exact=False, search_paths=True):