Search
Before delving into search, it's important to understand the concept of Hoppysearch records.
Hoppysearch records
Hoppysearch records consist of fields, which are key-value pairs that don't have to adhere to a specific schema and can vary from one record to another.
When creating your records, it's important to include information that will aid in search, filtering, relevance, and display on the frontend. You can omit any irrelevant fields.
Below is an example of a record with four fields:
- JSON
[
{
"product_name": "Samsung Galaxy M32",
"category": "Mobiles",
"brand": "Samsung",
"price": 14999,
"discount": 10,
"description": "The Samsung Galaxy M32 comes with a stunning 6.4-inch Full HD+ Super AMOLED display, a powerful 6000mAh battery, and a versatile 64MP quad-camera setup.",
"seller_name": "OmniTechRetail",
"rating": 4.5,
"num_ratings": 1000,
"in_stock": true,
"color": "Black",
"storage_capacity": "128GB",
"ram": null,
"processor": "MediaTek Helio G80",
"connectivity": "4G LTE"
}
]
While there may be many other fields, you only need to include the ones that are relevant to your search. This allows you to send us only the necessary key-value pairs.
Searchable Fields
Searchable fields are the key-value pairs in your records that contain the terms your users search for. For example, if a user searches for "software engineer," fields like title and description that contain those keywords become important.
Descriptive fields that contain searchable keywords, such as description is useful for improving search results.
By default, all fields are searchable, allowing you to search in your records from the outset. However, for better relevance and performance, it is recommended that you be more selective in designating only some fields as searchable. This can be done using the searchable fields feature under Rule section. To get proper step, refer Searchable Fields page. Additionally, this setting can be used to rank searchable fields, giving greater weight to some fields than others.
Fields for Displaying
In order to display images in your search results, you need to have an image fields in your records. This allows HoppySearch to return the image along with other fields in the search results, which can then be used directly on the frontend. HoppySearch returns all fields of the matched result, giving you the flexibility to choose which fields to use based on your specific use case.
It's important to note that searchable and displayed fields are two distinct concepts. Searchable fields are the fields on which you want to perform search operations, while displayed fields are the fields that you receive in the matched search results. By being selective with your searchable and displayed fields, you can improve the relevance and performance of your search experience.
Search Options Through HoppySearch UI
HoppySearch offers two types of search options to cater to different search requirements: Simple Query Search and Lucene Query Search.
Simple Query Search is a straightforward search method that doesn't require any knowledge of Lucene query syntax. On the other hand, Lucene Query Search is a powerful search method that allows for constructing complex queries using Lucene query syntax. By offering both search options, HoppySearch provides flexibility and power to help users find exactly what they are looking for.
Switching Between Search Options:
HoppySearch provides the flexibility to switch between Simple Query Search and Lucene Query Search, depending on your search requirements.
- By default, the Simple Query Search option is available in the search bar.
- If you want to switch to Lucene Query Search, click on the hyperlink below the search bar that says "Click here to switch to 'Lucene Query Search'".
- You can easily switch back and forth between the two search options as needed by clicking on the respective hyperlink.
Click here to switch to "Lucene Query Search"
Click here to switch to "Simple Query Search"
Using Simple Query Search:
Simple Query Search is a straightforward search method that converts your query to a Lucene query, without requiring you to write complex Lucene queries. HoppySearch will convert the queries to powerful lucene query internally. Follow below steps to use this search.
- Enter the word or phrase you want to search in the search bar.
- HoppySearch will convert your query to a Lucene query and display the relevant search results.
Using Lucene Query Search:
Lucene Query Search is a highly customizable search method that enables you to achieve more precise search results by constructing complex queries using Lucene query syntax. This syntax provides a broad range of search operators and functions.
To use Lucene Query Search:
- Construct a query using the appropriate Lucene query syntax.
- Enter the query into the search bar.
- For example, a query might look like this: "description: engineer is a professional".
Keep in mind that Lucene Query Search requires familiarity with Lucene query syntax. Nonetheless, it provides a more advanced search experience, making it ideal for users who require sophisticated searches.
By providing both Simple Query Search and Lucene Query Search options, HoppySearch delivers flexibility and power to assist you in locating precisely what you need.
Search Options Using HoppySearch's API
HoppySearch provides an API that allows you to integrate its search functionality into your project with complete freedom. Using the API is a great option for those who want to customize their search functionality.
To use the HoppySearch API, follow these steps:
Step 1: Get the index endpoint
- Navigate to the HoppySearch indices page at https://hoppysearch.com/indices.
- Select the specific index on which you want to perform a search operation.
- Click on the "view" button.
- The index endpoint will be displayed, which you can use to query the search results from your project.
Step 2: Get the required API key
Integrating search functionality into your project with HoppySearch's API requires an API key. Here's how you can obtain one:
- Follow steps 1 to 3 from the Get the index endpoint section.
- Click on the "Access Management" tab.
- Select the "API Keys" tab.
- Choose a non-expired API key to use with your API.
Step 3: Do Search
If you're using HoppySearch's API for search functionality, there are two options available to you: Simple Query Search and Lucene Query Search.
To assist you with API testing, HoppySearch offers both a Postman Collection and a Swagger UI. Refer to Postman and Swagger to get access to these valuable tools.
Here's a breakdown of how to use the API for each query search option:
For Lucene Query Search
If you need to construct complex queries using Lucene query syntax, then Lucene Query Search is the option for you. Here's an example of how to use the API for Lucene Query Search:
- cURL
- Javascript - Fetch
- NodeJS - Axios
- Python - http.client
- Java - OkHttp
- PHP - cURL
curl --location '<index-endpoint>/v1/search?q=<query>&pageSize=10&pageIndex=0' \
--header 'Authorization: <api-key>'
var myHeaders = new Headers();
myHeaders.append("Authorization", "<api-key>");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("<index-endpoint>/v1/search?q=<query>&pageSize=10&pageIndex=0", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
const axios = require('axios');
let config = {
method: 'get',
maxBodyLength: Infinity,
url: '<index-endpoint>/v1/search?q=<query>&pageSize=10&pageIndex=0',
headers: {
'Authorization': '<api-key>'
}
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
import http.client
conn = http.client.HTTPSConnection("<index-endpoint>")
payload = ''
headers = {
'Authorization': '<api-key>'
}
conn.request("GET", "/v1/search?q=<query>&pageSize=10&pageIndex=0", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = RequestBody.create(mediaType, "");
Request request = new Request.Builder()
.url("<index-endpoint>/v1/search?q=<query>&pageSize=10&pageIndex=0")
.method("GET", body)
.addHeader("Authorization", "<api-key>")
.build();
Response response = client.newCall(request).execute();
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => '<index-endpoint>/v1/search?q=<query>&pageSize=10&pageIndex=0',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Authorization: <api-key>'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
To use this API, replace the following things:
- Replace with your own index endpoint.
- Replace with your own API key.
- Replace with the Lucene query you need for your search.
- Use any to test the API.
For Simple Query Search
If you need a simple and easy-to-use search option, Simple Query Search is the way to go. Here's an example of how to use the API for Simple Query Search:
- cURL
- Javascript - Fetch
- NodeJS - Axios
- Python - http.client
- Java - OkHttp
- PHP - cURL
curl --location '<index-endpoint>/v1/search?pageSize=5&pageIndex=0' \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '{
"luceneQuery": "<query>"
}'
var myHeaders = new Headers();
myHeaders.append("Authorization", "<api-key>");
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
"luceneQuery": "<query>"
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("<index-endpoint>/v1/search?pageSize=5&pageIndex=0", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
const axios = require('axios');
let data = JSON.stringify({
"luceneQuery": "<query>"
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: '<index-endpoint>/v1/search?pageSize=5&pageIndex=0',
headers: {
'Authorization': '<api-key>',
'Content-Type': 'application/json'
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
import http.client
import json
conn = http.client.HTTPSConnection("<index-endpoint>")
payload = json.dumps({
"luceneQuery": "<query>"
})
headers = {
'Authorization': '<api-key>',
'Content-Type': 'application/json'
}
conn.request("POST", "/v1/search?pageSize=5&pageIndex=0", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\r\n \"luceneQuery\": <query>");
Request request = new Request.Builder()
.url("<index-endpoint>/v1/search?pageSize=5&pageIndex=0")
.method("POST", body)
.addHeader("Authorization", "<api-key>")
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => '<index-endpoint>/v1/search?pageSize=5&pageIndex=0',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"luceneQuery": "<query>"
}',
CURLOPT_HTTPHEADER => array(
'Authorization: <api-key>',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
To use this API, replace the following things:
- Replace with your own index endpoint.
- Replace with your own API key.
- Replace with the query you need for your search.
- Use any to test the API.