"""
Hybrid Search
============

Combines semantic retrieval with keyword pre-filtering.
"""

from typing import List, Any


class HybridSearch:
    """
    Filters semantic candidates using keyword matching.
    """

    def __init__(self, keyword_boost: float = 0.2):
        self.keyword_boost = keyword_boost

    def filter(self, query: str, candidates: List[Any]) -> List[Any]:

        query_lower = query.lower()
        filtered = []

        for chunk in candidates:
            text = ""

            if hasattr(chunk, "code") and chunk.code:
                text += chunk.code.lower()

            if hasattr(chunk, "docstring") and chunk.docstring:
                text += chunk.docstring.lower()

            if query_lower in text:
                filtered.append(chunk)

        # If nothing matched, fallback to semantic
        return filtered if filtered else candidates
