Mercurial > code > home > repos > sco-bot
view search/search_apex.py @ 8:f23b21bd0fce
apex search
author | drewp@bigasterisk.com |
---|---|
date | Sun, 07 Jul 2024 16:26:56 -0700 |
parents | |
children | d1b54241a731 |
line wrap: on
line source
from pprint import pprint from typing import Iterable from apexsearch import ApexSearch class Search: def __init__(self): self.apex = ApexSearch('data/apex', tables={ "docs": { "content": ["phrase"], "title": "title", "extras": ["sourceFile", "pos"], } }, id_field='id') def rebuild(self, docs: Iterable): self.apex.build_complete_index(lambda *a: docs) print('rebuild complete') def search(self, q:str): res= self.apex.search(q ,target_number=100) pprint(res) for row in res['results']: yield {'title':row['title'], 'snippetHtml':row['highlighted_content']}