import dataclasses


@dataclasses.dataclass(order=True)
class SearchMatch:
    distance: float
    ngram: str

    @classmethod
    def combine_matches(cls, matches):
        ngrams, distances = zip(*((match.ngram, match.distance) for match in matches))
        return cls(
            ngram=', '.join(ngrams),
            distance=sum(distances)/len(distances)   
        )

@dataclasses.dataclass
class QueryResult:
    id: int
    distance: float
    ngram: str
