GithubHelp home page GithubHelp logo

algolia / algoliasearch-helper-js Goto Github PK

View Code? Open in Web Editor NEW
174.0 83.0 46.0 8.41 MB

Helper for implementing advanced search features with Algolia

Home Page: https://instantsearchjs.netlify.app/algoliasearch-helper-js/

License: MIT License

JavaScript 90.12% HTML 0.34% Shell 0.27% Pug 2.01% Handlebars 0.66% SCSS 6.53% TypeScript 0.06%
algolia javascript state-management search

algoliasearch-helper-js's Introduction

algoliasearch-helper-js's People

Contributors

alexkirsz avatar aymeric-giraudet avatar bobylito avatar cmgchess avatar dhayab avatar dzello avatar eunjae-lee avatar fitztrev avatar francoischalifour avatar greenkeeperio-bot avatar haroenv avatar jerska avatar jerskouille avatar kokliko avatar lukyvj avatar marieglr avatar maxiloc avatar olance avatar pixelastic avatar rayrutjes avatar redox avatar renovate[bot] avatar robertmogos avatar samouss avatar sarahdayan avatar sergey-alekseev avatar timkelty avatar tkrugg avatar vvo avatar yannickcr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

algoliasearch-helper-js's Issues

What about numeric facettings ?

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.

Labels, values and i18n

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.

Seems that attributesToRetrieve and attributesToHighlight are ignored completely

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?

Remove holdSearch parameter!

See #36 for complete discussion.

Expected API :

helper.setDisjunctiveRefine( "facet1", "value" )
      .setQuery( "some input" )
      .search();
  • Remove holdsearch parameter
  • Remove autosearch magic
  • Create a setQuery function and let search be the method that executes the search
  • Make mutation API chainable
  • Update tests
  • Update samples

add algoliasearchHelper.version

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.

  • add .version property on the helper, reading package.json.version
  • use packageify transform to read and append version

setTypoTolerance

We cannot change the typoTolerance attribute. This is useful when we want to automatically search on ID

Remove extraQueries in v2

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.

Refresh method

Create a method to be able to refresh the results : execute the same query as in the current state of the helper.

Handle the URL Parameters

Have an optional way to:
Load the params of the state from URL hash
Set the URL hash when state changes

Missing setter for search result page size

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});

Batch queries and helper

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!

Avoid callback for outdated queries

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.

Fix the case where the distinct is applicable

@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;
}

The `processingTimeMS` should be summed

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.

Removing of refinements

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.

Sort facets values

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) { /* */ } }
   ]
}

The response should treated with the same parameters used for the request

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 :

  • bind the state to the callback. Because the state is immutable (in theory), each state is independent. here it might not work because of arrays. Have to dig a bit here.
  • debounce over a few ms the internal search function. This will work but will add some complexity and magic.
  • cancel first request if we are initiating a new search. Could have positive side effects on weird latency issues. I think it's feasible, must check.

support promises

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?").

Persistent facets

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.

Use an immutability library for arrays and objects in SearchParameters

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...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.