Search Operations
Searching for data within your HoppySearch index is a fundamental part of harnessing the power of HoppySearch. This JavaScript/Node.js client offers two types of search operations to cater to users with varying levels of familiarity with Lucene syntax:
- Normal Search
- Lucene Search
Let's explore how to use each of these search operations effectively.
1. Normal Search:
Normal search is designed for users who may not be familiar with Lucene syntax and want to perform searches with plain words or phrases.
How to Use Normal Search
-
Initial Configuration:
- Before you can use Normal Search, ensure you have configured your HoppySearch client as detailed in the initial setup documentation.
-
Perform Normal Search:
- To initiate a Normal Search, you only need to specify the word(s) you want to search for. Use the following code example:
- JavaScript
const query = "sweet from West Bengal"
const optionals = {
searchableKeyList: "about, ingredients",
diag: true,
showStats: true,
pageSize: 10,
pageIndex: 0
}
hoppysearch.search(query, optionals)
.then(res => {
console.log('statusCode:', res.status);
console.log('response text:', res.body);
})
.catch(err => {
console.log(err)
})-
query:
The word or words you want to search. -
searchableKeyList:
Specify on which key(s) you want to perform the search operation. -
diag:
- true: Allows you to see extra diagnostics records.
- false: Omits diagnostics records.
-
showStats:
- true: Provides statistics about the search operation.
- false: Excludes statistics.
-
pageSize and pageIndex: These parameters allow you to paginate search results.
The second argument of hoppysearch.search is not mandatory. You can customize your search experience according to your specific requirements.
2. Lucene Search:
Lucene Search offers advanced query customization for users who want to utilize the full power of Lucene queries while keeping the format simple and accessible.
How to Use Lucene Search
-
Initial Configuration:
- As with Normal Search, make sure your HoppySearch client is configured following the steps in the initial setup documentation.
-
Perform Lucene Search:
-
To use Lucene Search, you can write customized Lucene queries without worrying about Lucene setup. Follow the code example below:
-
- JavaScript
const luceneQuery = "ingredients: Maida"
const optionals = {
defaultKeyNameToBeSearch: "about",
analyzerClass: "org.apache.lucene.analysis.standard.StandardAnalyzer",
diag: true,
showStats: true,
pageSize: 10,
pageIndex: 0
}
hoppysearch.luceneSearch(luceneQuery, optionals)
.then(res => {
console.log('statusCode:', res.status);
console.log('response text:', res.body);
})
.catch(err => {
console.log(err)
}) -
luceneQuery: Write your customized Lucene query.
-
defaultKeyNameToBeSearch: If you only provide words, it will search under this default key.
-
analyzerClass: If you want to use a specific analyzer during the search, specify it here.
-
diag:
- true: Allows you to see extra diagnostics records.
- false: Omits diagnostics records.
-
showStats:
- true: Provides statistics about the search operation.
- false: Excludes statistics.
-
pageSize and pageIndex: These parameters allow you to paginate search results.
-
The second argument of hoppysearch.luceneSearch is not mandatory, enabling you to customize your search experience according to your specific needs.
These two search operations offer flexibility and advanced features, catering to users with varying levels of familiarity with Lucene. Whether you prefer a simple word-based search or need the advanced capabilities of Lucene queries, HoppySearch has you covered.
Use these search operations to unlock the full potential of your HoppySearch index and quickly retrieve the data you need.