Skip to main content

Search Operations with HoppySearch

Performing searches within your HoppySearch index is a breeze with the HoppySearch Python client. Whether you're new to search queries or want to dive into advanced searches using Lucene syntax, HoppySearch simplifies the process. This guide covers two types of search operations: Normal Search and Lucene Search.

Normal Search is designed for users who may not be familiar with Lucene query syntax. It allows you to perform searches by entering simple words or phrases. Follow the instructions below to perform a Normal Search:

Make sure you have completed the initial configuration setup, then use the following code:

const query = "sweet from West Bengal"
const optionals = {
searchableKeyList: "about, ingredients",
"diag": "true",
"showStats": "true",
"pageSize": 10,
"pageIndex": 0
}

try:
response = hoppysearch.search(query, optionals)
print(response)
except ApiException as e:
print("Exception: %s\n" % e)

Understanding the Code

  • query: The word or words you want to search for within your indexed data.
  • optionals: A dictionary containing optional parameters for the search operation.
    • searchableKeyList: The list of keys where the search operation should be performed.
    • diag: Set to "true" to see extra diagnostics records, or "false" to omit diagnostics.
    • showStats: Set to "true" to receive statistics about the search, or "false" to omit stats.
    • pageSize and pageIndex: Provide these parameters to paginate the search results.

Note

The second argument of the hoppysearch.searchfunction is not mandatory. You can omit it entirely or skip any key-value pair according to your requirements.

Lucene Search provides advanced search capabilities using Lucene query syntax. This option is ideal for users who require precise control over their search queries. Follow these steps to perform a Lucene Search:

Make sure you have completed the initial configuration setup, then use the following code:

const luceneQuery = "ingredients: Maida"
const optionals = {
defaultKeyNameToBeSearch: "about",
"analyzerClass": "org.apache.lucene.analysis.standard.StandardAnalyzer",
"diag": True,
"showStats": True,
"pageSize": 10,
"pageIndex": 0
}

try:
response = hoppysearch.lucene_search(luceneQuery, optionals)
print(response)
except ApiException as e:
print("Exception: %s\n" % e)

Understanding the Code

  • luceneQuery: Your customized Lucene query to perform a specific search operation.
  • optionals: A dictionary containing optional parameters for the Lucene search operation.
    • defaultKeyNameToBeSearch: The key under which the search will be performed if no specific key is provided.
    • analyzerClass: Use this to specify a specific Lucene analyzer for the search.
    • diag, showStats, pageSize, and pageIndex: Similar to the options in normal search.

Note

The second argument of the hoppysearch.lucene_search function is not mandatory. You can omit it entirely or skip any key-value pair according to your requirements.