This project has moved and is now part of the InstantSearch monorepo! The library remains unchanged and is still available on npm and CDNs like jsDelivr.
You can browse the code, find existing issues and follow new releases over there.
Helper for implementing advanced search features with Algolia
Home Page: https://instantsearchjs.netlify.app/algoliasearch-helper-js/
License: MIT License
This project has moved and is now part of the InstantSearch monorepo! The library remains unchanged and is still available on npm and CDNs like jsDelivr.
You can browse the code, find existing issues and follow new releases over there.
To be able to build such facet tree without messy code.
(originally by @redox on algolia/algoliasearch-client-javascript#35)
Can you have a look why @bobylito?
We need it for V3 release of course.
V2 is event based, but what is an extra query in this context. Does it still make sense?
add functions to handle numeric filters
It be nice to be able to remove all refinements for a particular facet (conjunctive or disjunctive) without having to modify the helper refinements object from outside the helper.
I tried with these options:
{
"hitsPerPage": 12,
"attributesToRetrieve":"nam1,field1,field2",
"attributesToHighlight":"name"
}
The response contains all the fields irrespective of the specified fields: name, field1 and field2.
The query param does not contain the attributesToRetrieve param as well.
Any other way to set these attributes?
Same as isExclude or isRefine but for disjunctive facets.
Previously in algoalisearch v2 we had AlgoliaExplainResults.
Would it be a good idea to reimplement it in the upcoming V2 helper?
We can't use the distinct flag set to true when the query is empty because the algolia engine returns an error. Why don't we change this parameter automatically when the query is empty or if we do not use filters?
Just in case, we need to ensure we cherry picked algolia/algoliasearch-client-javascript@b896bf3 and algolia/algoliasearch-client-javascript@11cecaa.
Commits were done on js client master branch after starting working on V3
As the algoliasearch client support both promises and callbacks.
As the helper is a smart wrapper around our JavaScript client.
It would be great for the helper to support both promises and callbacks as the API it's wrapping.
So that we can write examples using both callbacks and promises and people never complain about one or another missing implementation ("I am using promises on the client, why can't I have promises in the helper?").
Although the state is mostly immutable in SearchParameters, the inner structures based on array and objects are not due to their nature of native objects. It would be nice to use a library like Immutable to change the implementations of those structures. We could also benefits from data structures like Set or OrderedMap.
We should also make sure to leak the very minimal amount of abstractions to the users...
In SearchParameters/index.js:removeNumericRefinement
, the parameter value
is never used, and the if ( value )
might evaluate to false if the numeric filter value is 0.
See _.isUndefined
I did not find any documentation/sample on setting page size of search result. It will be great if someone creates a better documentation to make it more usable. For the time being I used the following workaround:
helper.search(query, function (err, content) {/* callback */}, {hitsPerPage:12});
Add a last parameter "holdSearch" to the state mutating methods of the helper.
helper.toggleRefine( "facet1", "value1", true);
helper.toggleRefine( "facet2", "valueA", true);
helper.search();
When we do a refinement right now, it doesn't reset the current, leading to inconsistencies.
If you make programmatically make two request with the helper, the first response will use the state of the second request.
Example :
helper.clearDisjunctiveRefine( "facet", "value1" );
helper.addDisjunctiveRefine( "facet", "value2" );
This will end up in the clear response to be treated as if there was a refinement expecting a second request.
Workaround : use the 'holdSearch' flag to keep the helper from doing two requests
helper.clearDisjunctiveRefine( "facet", "value1", true );
helper.addDisjunctiveRefine( "facet", "value2" );
Possible fixes :
@redox said :
Beware, you can use distinct=true if there are no facet filters, but some tag filters or some numeric filters or a query.
So probably something like:
if (!query && facetFilters.length === 0 && numericFilters.length === 0 && tagFilters.length === 0) {
distinct = false;
}
There is no guarantee on the order of the facets for the moment. The user has to manually sort its facets...
Right now, if we want a slider, we have an issue : a disjunctiveFacet
doesn't ignore the numericRefinements
on itself, which could make sense in some cases, but kills the whole idea of using facetting for this since the facet stats which come back take into account the newly created numericRefinements
. How do we handle it ?
This question might also bring the same question with facetsExcludes
, but I'm pretty sure that I we exclude a value from a disjunctive facet, we really don't want it at all.
When the component is updated the component should emit an "state-changed" event.
Copy of @redox suggestion :
Would be cool to be able to sort the values as well. I want my facet1 values sorted by count (default) and my facet2 values sorted by lexicographical order for instance.
{
facets: [ "facet1", "facet2" ] // default sort order
}
or
{
facets: [
{attribute: "facet1", sortFunction: Helper.sortByCountDesc },
{attribute: "facet2", sortFunction: Helper.sortByValueAsc },
{attribute: "facet3", sortFunction: function custom(a, b) { /* */ } }
]
}
One problem with the helper is that it's a black box that does queries without letting the user know how many operations it'll actually do on Algolia.
It's always very interesting to be able to see the module.version from the build.
We did it in the js client like that: https://github.com/algolia/algoliasearch-client-js/blob/f5068b73c23c1c812e16f702648593883b56de84/src/create-algoliasearch.js#L13.
It's using a browserify transform named packageify
, that includes only the version, not the full package.
getRankingInfo is a flag of the API that asks the engine to give informations about timeouts in queries. Such information is useful to know is the facets_stats are estimated or accurate.
Depending on the network, it may happen that a request sent before another is received after. This should not happen, and shouldn't be left to the responsibility of the user.
When we're dealing with disjunctive refinements, it generates multiple queries -> we need to sum the processingTimeMS of each answer to compute the final one.
At some we want to be able to retrieve and sort the values of a facet (see #38). This is great but it doesn't to provide another layer of indirections that can happen if we do internationalisation. In this case the values stored in Algolia are ID's not human readable values. And of course, some sort should apply on those values and not on ID's.
So long story short, we need to provide a way (in a second step) to not only fetch the values sorted but provide an i18n mechanism so we can sort the translated values.
It works fine except when facetting an array attribute.
Something like:
helper.clearRefinements(function(facet, value) {
return facet === "foo" && value.indexOf("bar") === 0;
});
imported from algolia/algoliasearch-client-javascript#33
The algolia API has the ability to set multiple values for a single parameter with or and and. https://www.algolia.com/doc#numericFilters
The helper api should be simple and not json based :P ๐ด
Like toggleRefine
and others ?
Add functions to set and get the value for any parameters that will be used for the the search.
Have an optional way to:
Load the params of the state from URL hash
Set the URL hash when state changes
Hey,
Using the helper with batch queries doesn't feel very natural right now. You have a "main" query, which can use all methods like toggleRefine(), and "extra" queries which cannot.
Do you think it'd be possible to make the helper handle all queries the same way?
Thanks!
We cannot change the typoTolerance attribute. This is useful when we want to automatically search on ID
Replace batch to new search api.
Create a method to be able to refresh the results : execute the same query as in the current state of the helper.
See #36 for complete discussion.
Expected API :
helper.setDisjunctiveRefine( "facet1", "value" )
.setQuery( "some input" )
.search();
Search should be usable for triggering search with existing parameters as well as for doing a one time override of the search parameters.
There are questions around the use of the extraQueries. So we might as well get rid of them for initial v2 and reintroduce later in a better form.
In the case of menus, we want to be able to keep the reference to certain facets. But that's a pretty boring task that can be handled in the helper.
For this, it would be great that we can define some facets as persistent when we initialize the helper. It would need to trigger a blank search once, and cache the results. Those cached results will be then served through the search results object with some function or information to evaluate if the facet is available with the current search.
Test case on the sample ( http://algolia.github.io/algoliasearch-helper-js/examples/instantsearch+helper.html ):
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.