Skip to content

Commit fcec32f

Browse files
committed
Refactor search logic - simplify expensive query detection and focus on specific terms
1 parent ca37e62 commit fcec32f

File tree

1 file changed

+1
-22
lines changed
  • openlibrary/plugins/worksearch

1 file changed

+1
-22
lines changed

openlibrary/plugins/worksearch/code.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -803,28 +803,7 @@ def _is_expensive_search(self, i):
803803
bool: True if this is an expensive search, False otherwise
804804
"""
805805
q = i.get('q', '').strip()
806-
807-
# Check for specialized Solr syntax patterns
808-
expensive_patterns = [
809-
r'language:', # language: queries
810-
r'\*:\*', # Wildcard queries
811-
r'[\[\{]', # Range queries with [ or {
812-
r'\bAND\b', # Boolean operators
813-
r'\bOR\b',
814-
r'\bNOT\b',
815-
]
816-
817-
for pattern in expensive_patterns:
818-
if re.search(pattern, q, re.IGNORECASE):
819-
return True
820-
821-
# Check for field-specific queries while excluding URL schemes
822-
# Matches patterns like 'field:value' but not 'http://', 'https://', 'ftp://', 'mailto:'
823-
if re.search(r'(?<![:/])\b(?!(?:https?|ftp|mailto)://)\w+:', q, re.IGNORECASE):
824-
return True
825-
826-
# Check if language filter is being used
827-
return bool(i.get('language'))
806+
return any(term in q for term in ['ebook_access:', 'language:'])
828807

829808

830809
def works_by_author(

0 commit comments

Comments
 (0)