Add cables to meilisearch db
This commit is contained in:
11
search.py
11
search.py
@@ -1,8 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
"""Interactions with the Meilisearch API for adding and searching cables."""
|
||||
from meilisearch import Client
|
||||
from meilisearch.task import TaskInfo
|
||||
from meilisearch.errors import MeilisearchApiError
|
||||
import json
|
||||
import time
|
||||
|
||||
DEFAULT_URL = "http://localhost:7700"
|
||||
DEFAULT_APIKEY = "fluffybunnyrabbit" # I WOULD RECOMMEND SOMETHING MORE SECURE
|
||||
@@ -34,12 +36,15 @@ class JukeboxSearch:
|
||||
# create the index if it does not exist already
|
||||
try:
|
||||
self.client.get_index(self.index)
|
||||
self.client.delete_index(self.index)
|
||||
self.client.create_index(self.index)
|
||||
except MeilisearchApiError as _:
|
||||
self.client.create_index(self.index)
|
||||
# make a variable to easily reference the index
|
||||
self.idxref = self.client.index(self.index)
|
||||
|
||||
time.sleep(0.05)
|
||||
# update filterable attributes if needed
|
||||
self.idxref.update_distinct_attribute('partnum')
|
||||
self.update_filterables(filterable_attrs)
|
||||
|
||||
def add_document(self, document: dict) -> TaskInfo:
|
||||
@@ -114,4 +119,4 @@ class JukeboxSearch:
|
||||
|
||||
# entrypoint
|
||||
if __name__ == "__main__":
|
||||
jbs = JukeboxSearch()
|
||||
jbs = JukeboxSearch()
|
||||
|
||||
Reference in New Issue
Block a user