Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set a default query to search #1395

Closed
sunel opened this issue Oct 6, 2016 · 3 comments
Closed

How to set a default query to search #1395

sunel opened this issue Oct 6, 2016 · 3 comments

Comments

@sunel
Copy link

sunel commented Oct 6, 2016

I am trying to set a default query to search instead of a empty search?

As i have pretty urls my search query will be like this

www.site.com/search/book instead of www.site.com/search?q=book

so i cant have the url sync enabled, so I have set urlSync to false. Now the inital query that is been passed is empty as it cant ready the url.

Is there a way to set the query before the search i been triggred.

i tried using the helper from the searchFunction but the api for the helper is totally diff from algoliasearchHelper

@sunel sunel closed this as completed Oct 7, 2016
@sunel sunel reopened this Oct 7, 2016
@vvo
Copy link
Contributor

vvo commented Oct 7, 2016

Is there a way to set the query before the search i been triggred.

Yes, you could try to do this:

var search = instantsearch({
  searchFunction(helper) {
    if (firstLoad) {
      search.helper.setQuery('book');
      helper.search();
    }
  }   
});

This is tricky as an API I must say, should work though.

@sunel
Copy link
Author

sunel commented Oct 7, 2016

Will try this

mean while when i went through the code found this for SearchParameters

{
   "query": "book",
   "disjunctiveFacets": [
      "customerReviewCount",
      "category",
      "salePrice_range",
      "manufacturer"
  ],
   "maxValuesPerFacet": 30,
   "page": 0,
   "hitsPerPage": 10,
   "facets": [
      "type",
      "shipping"
  ]
}

@vvo
Copy link
Contributor

vvo commented Oct 7, 2016

Yep this should work also, unsure if you are then able to override the query, try it and close the issue if solved. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants