mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
feat: Improve query matching in OPDS entries for enhanced search functionality
This commit is contained in:
@@ -930,23 +930,24 @@ class CalibreOPDSClient:
|
|||||||
def _entry_matches_query(entry: OPDSEntry, tokens: List[str]) -> bool:
|
def _entry_matches_query(entry: OPDSEntry, tokens: List[str]) -> bool:
|
||||||
if not tokens:
|
if not tokens:
|
||||||
return True
|
return True
|
||||||
haystack_parts: List[str] = []
|
search_fragments: List[str] = []
|
||||||
if entry.title:
|
if entry.title:
|
||||||
haystack_parts.append(entry.title)
|
search_fragments.append(entry.title.strip().lower())
|
||||||
if entry.authors:
|
|
||||||
haystack_parts.extend(entry.authors)
|
|
||||||
if entry.series:
|
if entry.series:
|
||||||
haystack_parts.append(entry.series)
|
search_fragments.append(entry.series.strip().lower())
|
||||||
if entry.summary:
|
for author in entry.authors:
|
||||||
haystack_parts.append(entry.summary)
|
cleaned = (author or "").strip()
|
||||||
if entry.tags:
|
if not cleaned:
|
||||||
haystack_parts.extend(entry.tags)
|
continue
|
||||||
if entry.alternate and entry.alternate.title:
|
lower_value = cleaned.lower()
|
||||||
haystack_parts.append(entry.alternate.title)
|
search_fragments.append(lower_value)
|
||||||
combined = " ".join(part for part in haystack_parts if part).lower()
|
for part in re.split(r"[\s,]+", lower_value):
|
||||||
if not combined:
|
part = part.strip()
|
||||||
|
if part:
|
||||||
|
search_fragments.append(part)
|
||||||
|
if not search_fragments:
|
||||||
return False
|
return False
|
||||||
return all(token in combined for token in tokens)
|
return all(any(token in fragment for fragment in search_fragments) for token in tokens)
|
||||||
|
|
||||||
def _filter_feed_entries(self, feed: OPDSFeed, query: str) -> OPDSFeed:
|
def _filter_feed_entries(self, feed: OPDSFeed, query: str) -> OPDSFeed:
|
||||||
normalized = (query or "").strip().lower()
|
normalized = (query or "").strip().lower()
|
||||||
|
|||||||
Reference in New Issue
Block a user