|
16 | 16 | from lib import ail_logger |
17 | 17 | from lib.ConfigLoader import ConfigLoader |
18 | 18 | from lib.objects import Domains |
| 19 | +from lib.objects import Images |
19 | 20 | from lib.objects import Items |
20 | 21 | from lib.objects import Messages |
| 22 | +from lib.objects import Screenshots |
21 | 23 | from lib import chats_viewer |
22 | 24 |
|
23 | 25 | logging.config.dictConfig(ail_logger.get_config(name='ail')) |
@@ -66,7 +68,7 @@ def get_indexes(self): |
66 | 68 | return self.client.get_indexes() |
67 | 69 |
|
68 | 70 | def _create_indexes(self): |
69 | | - for index in ['cdiscord', 'ctelegram', 'cmatrix', 'tor', 'web']: # TODO dynamic load of chat uuid ? |
| 71 | + for index in ['cdiscord', 'ctelegram', 'cmatrix', 'desc:dom', 'desc:img', 'desc:screen', 'tor', 'web']: # TODO dynamic load of chat uuid ? |
70 | 72 | self.client.create_index(index, {'primaryKey': 'uuid'}) |
71 | 73 |
|
72 | 74 | def add(self, index, document): |
@@ -96,8 +98,11 @@ def index_all(): |
96 | 98 | # Engine._delete('tor') |
97 | 99 | # Engine._delete('web') |
98 | 100 | Engine._create_indexes() |
99 | | - index_crawled() |
100 | | - index_chats_messages() |
| 101 | + # index_crawled() |
| 102 | + # index_chats_messages() |
| 103 | + index_images_descriptions() |
| 104 | + index_screenshots_descriptions() |
| 105 | + # index_domains_descriptions() |
101 | 106 |
|
102 | 107 | # TODO index titles |
103 | 108 | def _index_crawled_domain(dom_id): |
@@ -133,6 +138,43 @@ def index_chats_messages(): |
133 | 138 | for message in chats_viewer.get_messages_iterator(): |
134 | 139 | index_message(message) |
135 | 140 |
|
| 141 | + |
| 142 | +def index_image_description(image): |
| 143 | + index = f'desc:img' |
| 144 | + document = image.get_search_document() |
| 145 | + if document: |
| 146 | + Engine.add(index, document) |
| 147 | + |
| 148 | +def index_images_descriptions(): |
| 149 | + for image in Images.get_all_images_objects(): |
| 150 | + index_image_description(image) |
| 151 | + |
| 152 | + |
| 153 | +def index_screenshot_description(screenshot): |
| 154 | + index = f'desc:screen' |
| 155 | + document = screenshot.get_search_document() |
| 156 | + if document: |
| 157 | + Engine.add(index, document) |
| 158 | + |
| 159 | +def index_screenshots_descriptions(): |
| 160 | + for screenshot in Screenshots.get_screenshots_obj_iterator(): |
| 161 | + index_screenshot_description(screenshot) |
| 162 | + |
| 163 | + |
| 164 | +def index_domain_description(domain_id): |
| 165 | + index = f'desc:dom' |
| 166 | + domain = Domains.Domain(domain_id) |
| 167 | + document = domain.get_search_description_document() |
| 168 | + if document: |
| 169 | + Engine.add(index, document) |
| 170 | + |
| 171 | +def index_domains_descriptions(): |
| 172 | + for dom_id in Domains.get_domains_up_by_type('onion'): |
| 173 | + index_domain_description(dom_id) |
| 174 | + for dom_id in Domains.get_domains_up_by_type('web'): |
| 175 | + index_domain_description(dom_id) |
| 176 | + |
| 177 | + |
136 | 178 | def log(user_id, index, to_search): |
137 | 179 | logger.warning(f'{user_id} search: {index} - {to_search}') |
138 | 180 |
|
|
0 commit comments