vomebook commited on
Commit
eeb6f43
·
1 Parent(s): c4bafe1

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -47,6 +47,13 @@ def tokenize(text: str) -> list[str]:
47
  return list(set(re.findall(r"[a-z0-9]+|[\u4e00-\u9fff\u3400-\u4dbf]+", text_lower)))
48
 
49
 
 
 
 
 
 
 
 
50
  def build_first_match_snippet(text: str, query: str, window: int = 110) -> str:
51
  query = (query or "").strip()
52
  if not text or not query:
@@ -186,9 +193,9 @@ def search(q="", sources_filter=None, folders=None, min_size=None, max_size=None
186
  tokens = tokenize(q)
187
  if exact:
188
  if search_paths:
189
- indices = [idx for idx, rec in enumerate(records) if q.lower() in rec["_search_text"]]
190
  else:
191
- indices = [idx for idx, rec in enumerate(records) if q.lower() in rec["_file_search_text"]]
192
  else:
193
  matched = set()
194
  for token in tokens:
 
47
  return list(set(re.findall(r"[a-z0-9]+|[\u4e00-\u9fff\u3400-\u4dbf]+", text_lower)))
48
 
49
 
50
+ def matches_exact_query(text: str, query: str) -> bool:
51
+ if "*" in query or "?" in query:
52
+ pattern = re.escape(query).replace(r"\*", ".*").replace(r"\?", ".")
53
+ return re.search(pattern, text, re.IGNORECASE) is not None
54
+ return query.lower() in text.lower()
55
+
56
+
57
  def build_first_match_snippet(text: str, query: str, window: int = 110) -> str:
58
  query = (query or "").strip()
59
  if not text or not query:
 
193
  tokens = tokenize(q)
194
  if exact:
195
  if search_paths:
196
+ indices = [idx for idx, rec in enumerate(records) if matches_exact_query(rec["_search_text"], q)]
197
  else:
198
+ indices = [idx for idx, rec in enumerate(records) if matches_exact_query(rec["_file_search_text"], q)]
199
  else:
200
  matched = set()
201
  for token in tokens: