Add platform-specific query optimizations

- hackernews: use extract_core_subject instead of raw topic, add
  points>5 filter and restrictSearchableAttributes=title to reduce
  noise from URL-match and low-signal posts
- youtube: add --dateafter parameter to yt-dlp for server-side date
  filtering (Python soft filter still handles fallback)
- reddit: skip opinion/review query variant for how_to/comparison
  queries where it adds noise
- bird_x: add OR-group retry with compound terms before falling back
  to word-dropping (uses X OR operator for multi-concept queries)
- query.py: add detect_query_type() and extract_compound_terms()
This commit is contained in:
Jeffrey Sperling
2026-03-11 15:24:44 -07:00
parent c5be117701
commit 1002f1f020
6 changed files with 140 additions and 11 deletions
+45 -1
View File
@@ -6,7 +6,7 @@ from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent / "scripts"))
from lib.query import NOISE_WORDS, extract_core_subject
from lib.query import NOISE_WORDS, detect_query_type, extract_compound_terms, extract_core_subject
class TestExtractCoreSubject(unittest.TestCase):
@@ -126,5 +126,49 @@ class TestNoiseWordsCompleteness(unittest.TestCase):
self.assertIn(w, NOISE_WORDS)
class TestDetectQueryType(unittest.TestCase):
"""Tests for detect_query_type()."""
def test_comparison(self):
self.assertEqual(detect_query_type("React vs Vue"), "comparison")
def test_how_to(self):
self.assertEqual(detect_query_type("how to deploy on Vercel"), "how_to")
def test_opinion(self):
self.assertEqual(detect_query_type("cursor IDE worth it"), "opinion")
def test_product(self):
self.assertEqual(detect_query_type("cursor IDE pricing"), "product")
def test_concept_default(self):
self.assertEqual(detect_query_type("multi-agent reinforcement learning"), "concept")
def test_how_prefix(self):
self.assertEqual(detect_query_type("how does Claude work"), "how_to")
class TestExtractCompoundTerms(unittest.TestCase):
"""Tests for extract_compound_terms()."""
def test_hyphenated(self):
terms = extract_compound_terms("multi-agent reinforcement learning")
self.assertIn("multi-agent", terms)
def test_title_case(self):
terms = extract_compound_terms("Claude Code and React Native")
self.assertTrue(any("Claude Code" in t for t in terms))
self.assertTrue(any("React Native" in t for t in terms))
def test_no_compounds(self):
terms = extract_compound_terms("python tutorial")
self.assertEqual(len(terms), 0)
def test_multiple_hyphens(self):
terms = extract_compound_terms("vc-backed start-up")
self.assertIn("vc-backed", terms)
self.assertIn("start-up", terms)
if __name__ == "__main__":
unittest.main()