What is algoliasearch-helper?
The `algoliasearch-helper` package is a JavaScript library that provides a set of tools to manage search parameters and results when using Algolia's search API. It helps in building complex search interfaces by offering functionalities like managing search states, refining search queries, and handling pagination.
What are algoliasearch-helper's main functionalities?
Managing Search Parameters
This feature allows you to manage search parameters such as facets and disjunctive facets. The code sample demonstrates how to initialize the helper with specific facets and add a facet refinement to filter search results.
const algoliasearch = require('algoliasearch');
const algoliasearchHelper = require('algoliasearch-helper');
const client = algoliasearch('YourApplicationID', 'YourAdminAPIKey');
const index = client.initIndex('your_index_name');
const helper = algoliasearchHelper(client, 'your_index_name', {
facets: ['category'],
disjunctiveFacets: ['brand']
});
helper.addFacetRefinement('category', 'Books').search();
Handling Pagination
This feature helps in handling pagination of search results. The code sample shows how to set the page number and listen for the search results.
helper.setPage(2).search();
helper.on('result', function(content) {
console.log(content.hits);
});
Refining Search Queries
This feature allows you to refine search queries. The code sample demonstrates how to set a search query and listen for the search results.
helper.setQuery('Harry Potter').search();
helper.on('result', function(content) {
console.log(content.hits);
});
Managing Search States
This feature allows you to manage the search state. The code sample shows how to get the current search state and set a new search state.
const state = helper.getState();
console.log(state);
helper.setState({
query: 'Harry Potter',
page: 1
}).search();
Other packages similar to algoliasearch-helper
elasticlunr
Elasticlunr.js is a lightweight full-text search engine developed in JavaScript for browser search and offline search. It provides functionalities similar to Algolia but is more suited for smaller datasets and offline use cases.
lunr
Lunr.js is a small, full-text search library for use in the browser and Node.js. It offers functionalities for indexing and searching documents, similar to Algolia, but is designed for smaller datasets and does not require a server.
search-index
Search-index is a powerful search engine for Node.js that allows you to index and search documents. It provides similar functionalities to Algolia but is more flexible and can be used for a variety of search use cases.
algoliasearch-helper-js
This module is the companion of the algoliasearch-client-js. It helps you keep
track of the search parameters and provides a higher level API.
The helper is built on top of algoliasearch-client-js and this version is
specifically made to work with the newest V3 versions of it.
Features
- Search parameters tracking
- Facets exclusions
- Pagination
- Disjunctive facetting (search on two or more values for a single facet)
- Query batching
What does it look like?
A small example that uses Browserify to manage modules.
var algoliasearch = require( "algoliasearch" );
var algoliasearchHelper = require( "algoliasearch-helper" );
var client = algoliasearch( "app_id", "secret" );
var helper = algoliasearchHelper( client, "myMainIndex", {
facets : [ "mainCharacterFirstName", "year" ],
disjunctiveFacets : [ "director" ]
});
helper.on( "result", function( data ){
console.log( data.hits );
} );
helper.addDisjunctiveRefine( "director", "Clint Eastword" );
helper.addDisjunctiveRefine( "director", "Sofia Coppola" );
helper.addRefine( "year", "2003" );
helper.search( "" );
How to use this module
(See the examples in action)[http://algolia.github.io/algoliasearch-helper-js/]
Use with NPM
npm install algoliasearch-helper
Use with bower
bower install algoliasearch-helper
Use the CDN
Include this in your page :
<script src="//cdn.jsdelivr.net/algoliasearch.helper/2.0.0-rc1/algoliasearch.helper.min.js"></script>
How to contribute
- fork this repo
- clone the repository
git clone https://github.com/[your-handle-here]/algoliasearch-helper-js.git
- make your fix or feature
- launch the dev mode
npm run dev
- add a test for your feature (see /test folder)
- make sure, it goes through the linter without an error
npm run lint
- propose your pull request
- profit :)
A quick note though, even though we'll make our best to read and integrate your PR,
we may be a bit slow. Sorry :). We might also make some comments and discussions too,
for the best interest of this library. Thanks in advance for your contribution!