Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

feat(search): allow the search only with Derived Helpers #704

Merged
merged 4 commits into from
May 14, 2019

Conversation

samouss
Copy link
Contributor

@samouss samouss commented May 13, 2019

This PR introduces a new method called searchOnlyWithDerivedHelpers. As the name suggests the function allows to bypass the "main" instance search to only use the Derived Helpers. The main idea behind the API is to be able to control which state is used by the query, without having to alter the internal state of the helper (it would be useful for federated search for example). With the .derive API we have a full control on the query with the derivation function. We can alter the state without impact on the internal instance of the Helper.

I choose to implement this behavior with a dedicated method to limit the number of changes. We'll release a major version but we should keep the support of the original behavior because it will not only benefit InstantSearch.js. We also want to benefit the Lodash reduction in React InstantSearch.

const helper = algoliasearchHelper(client, 'index');
const derivedHelper = helper.derive(state => {
  // Alter the state without impact on the main instance
  return state;
});

helper.on('search', () => {
  // The search is not triggered on the main instance
});

derivedHelper.on('search', () => {
  // The search is only triggered on the derived instance
});

// Trigger only 1 queries vs 2 queries with a regular search
helper.searchOnlyWithDerivedHelpers();

@samouss samouss requested a review from a team May 13, 2019 07:46
@ghost ghost requested review from Haroenv and tkrugg and removed request for a team May 13, 2019 07:46
Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a breaking change, an reasoning makes sense to me

Copy link
Member

@francoischalifour francoischalifour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know the tests were originally named like this but they don't help understand what we expect from each test. Since we now use Jest we can use a describe and make the tests' name more explicit.

test/spec/algoliasearch.helper/derive/multiqueries.js Outdated Show resolved Hide resolved
test/spec/algoliasearch.helper/derive/multiqueries.js Outdated Show resolved Hide resolved
Co-Authored-By: François Chalifour <francoischalifour@users.noreply.github.com>
@samouss samouss merged commit 6ee3e28 into next May 14, 2019
@samouss samouss deleted the feat/controlled branch May 14, 2019 08:35
Haroenv pushed a commit that referenced this pull request Nov 18, 2019
* test(derive): use factory for the client

* feat(search): allow to search with derived helpers only

* test(derive): update names of the tests

* test(derive): remove extra wording

Co-Authored-By: François Chalifour <francoischalifour@users.noreply.github.com>
Haroenv added a commit that referenced this pull request Nov 18, 2019
 *  fix(merge): change implementation  (#716) 29c2138
 * chore: mention remaining changes f756947
 * chore(deps): update circleci/node:8.15.1 docker digest to ef1a0c4 (#715) f4dab89
 * chore(lodash): remove _.omit (#655) 7db8b4c
 * chore(lodash): remove lodash from dependency list (#705) a63ec6b, closes #552
 * chore(release): allow canary release (#712) 3eb087c
 * chore(removeHierarchicalFacetRefinement): remove error if not refined (#747) e68ecfe
 * chore: merge develop into master (#750) 53c7c62
 * chore: remove Bower support (#711) e7518e2
 * chore(ts): add methods d051f79
 * chore(ts): add ruleContexts to SP 4bdc4a4
 * chore(ts): add searchOnlyWithDerivedHelpers (#739) c6aa31b
 * chore(ts): publish definition file too 1813462
 * chore(TS): isNumericRefined has only one required argument cac8fc3
 * chore(warn): remove unused function (lodash.bind) (#682) c59b7e3
 * chore: update release command 0989880
 * docs: add link to wiki 3598f2a
 * docs: update event signature (#701) bbe4634
 * docs(migration): mention changed methods (#732) f95e680
 * docs(next): add migration guide 8430137
 * docs(serverUsed): mention getRankingInfo (#706) f258c2a, closes #500
 * feat: implement dedicated reset page method (#673) 666501e
 * feat(getState): remove filter option (#707) ac52791
 * feat(getState): remove getState (#708) 7de698c
 * feat(requestBuilder): prevent needless extra requests for empty refinements (#737) db0a392
 * feat(search): allow the search only with Derived Helpers (#704) aa128fc
 * feat(SearchParameters): avoid undefined values (#703) 9757e0a
 * feat(typescript): move typings inline (#719) a12272e
 * fix(defaults): remove const 48a0c48
 * fix(errors): remove isRefined (#731) 5761885
 * fix(getConjunctiveRefinements): no error when requested facet is not conjunctive (#724) cf852e7
 * fix(getDisjunctiveRefinements): remove error (#725) 211e390
 * fix(getExcludeRefinements): replace error by default value (#726) 9d7ae87
 * fix(getFacetStats): remove error (#721) 96b6ec8
 * fix(getFacetValues): don't throw error when there's no facet (#720) e15e39e
 * fix(getHierarchicalFacetBreadcrumb): don't throw an error (#723) 40e1d61
 * fix(isDisjunctiveFacetRefined): return false if not in disjunctiveFacets (#729) 13ec09b
 * fix(isExcludeRefined): remove error in favor of false (#728) 3f0ab6b
 * fix(isFacetRefined): return false if facet isn't declared (#727) 7151f56
 * fix(isHierarchicalFacetRefined): return false if refinement isn't a facet (#730) 89fa010
 * fix(lodash/intersection): replace with custom implementation (#718) 00dfb4e
 * fix(removeXFacet): make sure this fully removes empty arrays (#743) ea5a22a
 * fix(results): remove lodash looping over objects (#648) bb025c2, closes #258
 * fix(sortBy): compare whole prefix instead of first character (#702) b85fb50, closes #702
 * fix(toggleRefinement): keep an empty array when clearing (#738) 5b3fc11
 * fix(types): add state.removeNumericRefinement (#742) e58c24a
 * refactor(addAgent): remove duplicate code (#657) d023efd
 * refactor(error): use object vs list of arguments (#700) 722eceb
 * refactor(lodash): compact (#689) 284efa5
 * refactor(lodash): forOwn (#697) eae367a
 * refactor(lodash): intersection (#696) 25822a5
 * refactor(lodash): map & trim (#679) 357fcb7
 * refactor(lodash): merge (#694) 92bced4
 * refactor(lodash): partial & partialRight (#693) 7ceea2f
 * refactor(lodash): remove filter (#685) 249d2e6
 * refactor(lodash): remove flatten (#695) 9da0e08
 * refactor(lodash): remove forEach (#674) 8c93765
 * refactor(lodash): remove reduce (#678) 7907805
 * refactor(lodash): remove simple functions (#656) c309ffa
 * refactor(lodash): remove startsWith (#690) bb00933
 * refactor(lodash): replace defaults with pure alternative (#692) ee07132
 * refactor(lodash): replace find & findIndex (#687) 92e7c23
 * refactor(lodash): replace orderBy (#698) bb2b31e
 * refactor(lodash): sumBy (#688) a538bd9
 * refactor(result): use object vs list of arguments (#699) 643f18e
 * refactor(search): emit object (#683) 46c7d7d
 * refactor(searchForFacetValues): use object vs list of arguments (#684) ab8e9c5
 * refactor: remove getQueryParameter (#713) d9dfac4
 * refactor(searchOnce): use object vs list of arguments (#681) 42b40d3
 * refactor(SearchParameters): removes default values (#670) b15696b
 * refactor(url): remove url helpers (#652) 52e22f4
 * test(sffv): no longer test impossible responses (#686) fd878e8

### BREAKING CHANGE

* getState(filters) is replaced my manually filtering the returned object
* removed helper.isRefined, use helper.hasRefinements instead
* SearchParameters.filter is removed

* doc(filter): remove reference
* use helper.state instead of helper.getState()
dhayab pushed a commit to algolia/instantsearch that referenced this pull request Jul 10, 2023
…oliasearch-helper-js#704)

* test(derive): use factory for the client

* feat(search): allow to search with derived helpers only

* test(derive): update names of the tests

* test(derive): remove extra wording

Co-Authored-By: François Chalifour <francoischalifour@users.noreply.github.com>
dhayab pushed a commit to algolia/instantsearch that referenced this pull request Jul 10, 2023
 *  fix(merge): change implementation  (algolia/algoliasearch-helper-js#716) algolia/algoliasearch-helper-js@736c8ae
 * chore: mention remaining changes algolia/algoliasearch-helper-js@1f7ea90
 * chore(deps): update circleci/node:8.15.1 docker digest to ef1a0c4 (algolia/algoliasearch-helper-js#715) algolia/algoliasearch-helper-js@4b2c788
 * chore(lodash): remove _.omit (algolia/algoliasearch-helper-js#655) algolia/algoliasearch-helper-js@055257d
 * chore(lodash): remove lodash from dependency list (algolia/algoliasearch-helper-js#705) algolia/algoliasearch-helper-js@d1be213, closes algolia/algoliasearch-helper-js#552
 * chore(release): allow canary release (algolia/algoliasearch-helper-js#712) algolia/algoliasearch-helper-js@a72f0de
 * chore(removeHierarchicalFacetRefinement): remove error if not refined (algolia/algoliasearch-helper-js#747) algolia/algoliasearch-helper-js@89dc193
 * chore: merge develop into master (algolia/algoliasearch-helper-js#750) algolia/algoliasearch-helper-js@77e3e84
 * chore: remove Bower support (algolia/algoliasearch-helper-js#711) algolia/algoliasearch-helper-js@69d00a5
 * chore(ts): add methods algolia/algoliasearch-helper-js@3c4ee8f
 * chore(ts): add ruleContexts to SP algolia/algoliasearch-helper-js@bdb516e
 * chore(ts): add searchOnlyWithDerivedHelpers (algolia/algoliasearch-helper-js#739) algolia/algoliasearch-helper-js@1f5dd4c
 * chore(ts): publish definition file too algolia/algoliasearch-helper-js@4949596
 * chore(TS): isNumericRefined has only one required argument algolia/algoliasearch-helper-js@1d4e7fb
 * chore(warn): remove unused function (lodash.bind) (algolia/algoliasearch-helper-js#682) algolia/algoliasearch-helper-js@da805d9
 * chore: update release command algolia/algoliasearch-helper-js@3255f36
 * docs: add link to wiki algolia/algoliasearch-helper-js@f0915c3
 * docs: update event signature (algolia/algoliasearch-helper-js#701) algolia/algoliasearch-helper-js@1a0c343
 * docs(migration): mention changed methods (algolia/algoliasearch-helper-js#732) algolia/algoliasearch-helper-js@1c9bdcd
 * docs(next): add migration guide algolia/algoliasearch-helper-js@dfb08f0
 * docs(serverUsed): mention getRankingInfo (algolia/algoliasearch-helper-js#706) algolia/algoliasearch-helper-js@4a8d8f7, closes algolia/algoliasearch-helper-js#500
 * feat: implement dedicated reset page method (algolia/algoliasearch-helper-js#673) algolia/algoliasearch-helper-js@8fa4ee4
 * feat(getState): remove filter option (algolia/algoliasearch-helper-js#707) algolia/algoliasearch-helper-js@681bf17
 * feat(getState): remove getState (algolia/algoliasearch-helper-js#708) algolia/algoliasearch-helper-js@b951579
 * feat(requestBuilder): prevent needless extra requests for empty refinements (algolia/algoliasearch-helper-js#737) algolia/algoliasearch-helper-js@a03ff29
 * feat(search): allow the search only with Derived Helpers (algolia/algoliasearch-helper-js#704) algolia/algoliasearch-helper-js@3da864c
 * feat(SearchParameters): avoid undefined values (algolia/algoliasearch-helper-js#703) algolia/algoliasearch-helper-js@7812536
 * feat(typescript): move typings inline (algolia/algoliasearch-helper-js#719) algolia/algoliasearch-helper-js@68af05e
 * fix(defaults): remove const algolia/algoliasearch-helper-js@7df8754
 * fix(errors): remove isRefined (algolia/algoliasearch-helper-js#731) algolia/algoliasearch-helper-js@1da0000
 * fix(getConjunctiveRefinements): no error when requested facet is not conjunctive (algolia/algoliasearch-helper-js#724) algolia/algoliasearch-helper-js@b7c9a3f
 * fix(getDisjunctiveRefinements): remove error (algolia/algoliasearch-helper-js#725) algolia/algoliasearch-helper-js@c573d33
 * fix(getExcludeRefinements): replace error by default value (algolia/algoliasearch-helper-js#726) algolia/algoliasearch-helper-js@77f6770
 * fix(getFacetStats): remove error (algolia/algoliasearch-helper-js#721) algolia/algoliasearch-helper-js@3b593d7
 * fix(getFacetValues): don't throw error when there's no facet (algolia/algoliasearch-helper-js#720) algolia/algoliasearch-helper-js@cfdbc5b
 * fix(getHierarchicalFacetBreadcrumb): don't throw an error (algolia/algoliasearch-helper-js#723) algolia/algoliasearch-helper-js@4a75244
 * fix(isDisjunctiveFacetRefined): return false if not in disjunctiveFacets (algolia/algoliasearch-helper-js#729) algolia/algoliasearch-helper-js@7cb124d
 * fix(isExcludeRefined): remove error in favor of false (algolia/algoliasearch-helper-js#728) algolia/algoliasearch-helper-js@238e975
 * fix(isFacetRefined): return false if facet isn't declared (algolia/algoliasearch-helper-js#727) algolia/algoliasearch-helper-js@c2d8afe
 * fix(isHierarchicalFacetRefined): return false if refinement isn't a facet (algolia/algoliasearch-helper-js#730) algolia/algoliasearch-helper-js@0a913c7
 * fix(lodash/intersection): replace with custom implementation (algolia/algoliasearch-helper-js#718) algolia/algoliasearch-helper-js@dd63327
 * fix(removeXFacet): make sure this fully removes empty arrays (algolia/algoliasearch-helper-js#743) algolia/algoliasearch-helper-js@33f256c
 * fix(results): remove lodash looping over objects (algolia/algoliasearch-helper-js#648) algolia/algoliasearch-helper-js@f3287d8, closes algolia/algoliasearch-helper-js#258
 * fix(sortBy): compare whole prefix instead of first character (algolia/algoliasearch-helper-js#702) algolia/algoliasearch-helper-js@21fcd34, closes algolia/algoliasearch-helper-js#702
 * fix(toggleRefinement): keep an empty array when clearing (algolia/algoliasearch-helper-js#738) algolia/algoliasearch-helper-js@9ab228d
 * fix(types): add state.removeNumericRefinement (algolia/algoliasearch-helper-js#742) algolia/algoliasearch-helper-js@e8b4b34
 * refactor(addAgent): remove duplicate code (algolia/algoliasearch-helper-js#657) algolia/algoliasearch-helper-js@050a17f
 * refactor(error): use object vs list of arguments (algolia/algoliasearch-helper-js#700) algolia/algoliasearch-helper-js@c70d6ee
 * refactor(lodash): compact (algolia/algoliasearch-helper-js#689) algolia/algoliasearch-helper-js@7a5af0e
 * refactor(lodash): forOwn (algolia/algoliasearch-helper-js#697) algolia/algoliasearch-helper-js@a0af759
 * refactor(lodash): intersection (algolia/algoliasearch-helper-js#696) algolia/algoliasearch-helper-js@0077f50
 * refactor(lodash): map & trim (algolia/algoliasearch-helper-js#679) algolia/algoliasearch-helper-js@a8c5f2c
 * refactor(lodash): merge (algolia/algoliasearch-helper-js#694) algolia/algoliasearch-helper-js@7cb5357
 * refactor(lodash): partial & partialRight (algolia/algoliasearch-helper-js#693) algolia/algoliasearch-helper-js@151685d
 * refactor(lodash): remove filter (algolia/algoliasearch-helper-js#685) algolia/algoliasearch-helper-js@16a3aff
 * refactor(lodash): remove flatten (algolia/algoliasearch-helper-js#695) algolia/algoliasearch-helper-js@d2b667f
 * refactor(lodash): remove forEach (algolia/algoliasearch-helper-js#674) algolia/algoliasearch-helper-js@58fd08f
 * refactor(lodash): remove reduce (algolia/algoliasearch-helper-js#678) algolia/algoliasearch-helper-js@187ae67
 * refactor(lodash): remove simple functions (algolia/algoliasearch-helper-js#656) algolia/algoliasearch-helper-js@ed2a393
 * refactor(lodash): remove startsWith (algolia/algoliasearch-helper-js#690) algolia/algoliasearch-helper-js@75f1035
 * refactor(lodash): replace defaults with pure alternative (algolia/algoliasearch-helper-js#692) algolia/algoliasearch-helper-js@c5b0c89
 * refactor(lodash): replace find & findIndex (algolia/algoliasearch-helper-js#687) algolia/algoliasearch-helper-js@c190cb3
 * refactor(lodash): replace orderBy (algolia/algoliasearch-helper-js#698) algolia/algoliasearch-helper-js@7805cd8
 * refactor(lodash): sumBy (algolia/algoliasearch-helper-js#688) algolia/algoliasearch-helper-js@a037c6f
 * refactor(result): use object vs list of arguments (algolia/algoliasearch-helper-js#699) algolia/algoliasearch-helper-js@f4ea805
 * refactor(search): emit object (algolia/algoliasearch-helper-js#683) algolia/algoliasearch-helper-js@1029dcd
 * refactor(searchForFacetValues): use object vs list of arguments (algolia/algoliasearch-helper-js#684) algolia/algoliasearch-helper-js@d2acced
 * refactor: remove getQueryParameter (algolia/algoliasearch-helper-js#713) algolia/algoliasearch-helper-js@6b8c643
 * refactor(searchOnce): use object vs list of arguments (algolia/algoliasearch-helper-js#681) algolia/algoliasearch-helper-js@a86581a
 * refactor(SearchParameters): removes default values (algolia/algoliasearch-helper-js#670) algolia/algoliasearch-helper-js@2679f99
 * refactor(url): remove url helpers (algolia/algoliasearch-helper-js#652) algolia/algoliasearch-helper-js@b9e3fd9
 * test(sffv): no longer test impossible responses (algolia/algoliasearch-helper-js#686) algolia/algoliasearch-helper-js@09e475f

### BREAKING CHANGE

* getState(filters) is replaced my manually filtering the returned object
* removed helper.isRefined, use helper.hasRefinements instead
* SearchParameters.filter is removed

* doc(filter): remove reference
* use helper.state instead of helper.getState()
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants