Adding Data to HoppySearch Index
To make your data searchable with HoppySearch, you need to index it first. Indexing involves adding your data to HoppySearch so that it can be efficiently searched and retrieved. Below, you'll find instructions on how to add data to your HoppySearch index using the HoppySearch Python client.
Code Example
Use the following Python code to add data to your HoppySearch index after the initial configuration.
- python
documents = [
{
"image": "https://static.toiimg.com/thumb/55476463.cms?width=1200&height=900",
"name": "Balu shahi",
"about": "Balu shahi is a traditional sweet from West Bengal, made with a mixture of maida flour, yogurt, and oil...",
"ingredients": "Maida flour, yogurt, oil, sugar",
"state": "West Bengal",
"hs_guid": "1cc12c15-d680-4b73-b5b5-9235b4726ac6",
"url": "Badusha recipe | Balushahi recipe
}
]
optionals = {
"configType": "create",
"diag": "true"
}
try:
response = hoppysearch.index(documents, optionals)
print(response)
except ApiException as e:
print("Exception: %s\n" % e)
Understanding the Code
- documents: This list contains the documents you want to add to your HoppySearch index. Each document is represented as a dictionary with key-value pairs, where keys are field names (e.g., "image," "name," "about") and values are the corresponding data.
- optionals: This dictionary contains optional parameters for the indexing operation.
- configType: There are two options:
- create: Clears all existing data from the index and adds the provided data.
- append: Appends the provided data to the existing data without clearing.
- diag: Set to "true" if you want to see extra diagnostics records; set to "false" to omit diagnostics.
- configType: There are two options:
Important Note
The second argument of hoppysearch.index is not mandatory. You can skip it entirely or omit any key-value pair according to your requirements.
By using this code, you can efficiently add data to your HoppySearch index, making it searchable for various search operations.