8
|
1 from pprint import pprint
|
|
2 from typing import Iterable
|
|
3 from apexsearch import ApexSearch
|
|
4
|
|
5
|
|
6 class Search:
|
|
7
|
|
8 def __init__(self):
|
|
9 self.apex = ApexSearch('data/apex',
|
|
10 tables={
|
|
11 "docs": {
|
|
12 "content": ["phrase"],
|
|
13 "title": "title",
|
|
14 "extras": ["sourceFile", "pos"],
|
|
15 }
|
|
16 },
|
|
17 id_field='id')
|
|
18
|
|
19 def rebuild(self, docs: Iterable):
|
|
20 self.apex.build_complete_index(lambda *a: docs)
|
|
21 print('rebuild complete')
|
|
22
|
9
|
23 def search(self, q: str):
|
|
24 res = self.apex.search(q, target_number=100)
|
|
25 pprint(res)
|
8
|
26 for row in res['results']:
|
9
|
27 yield {
|
|
28 'title': row['title'],
|
|
29 'snippetHtml': row['highlighted_content']
|
|
30 }
|