typesense / typesense-instantsearch-adapter

A JS adapter library to build rich search interfaces with Typesense and InstantSearch.js
MIT License
403 stars 63 forks source link

additionalSearchParameters filterBy is not passed into the request #11

Closed arminus closed 3 years ago

arminus commented 3 years ago

Description

additionalSearchParameters filterBy is not passed into the request

Steps to reproduce

Starting with the sample code in https://github.com/typesense/typesense-instantsearch-demo/blob/master/src/app.js, I added an additionalSearchParameters filterBy like so:

  additionalSearchParameters: {
    queryBy: 'searchName',
    filterBy: 'type:=f',
  },

Expected Behavior

I'd expect that this is passed into my typesense endpoint

Actual Behavior

The actual request looks like this however:

https://<my-endpoint>/collections/trails/documents/search?query_by=searchName&filter_by=&highlight_full_fields=searchName&q=*&facet_by=&page=1

i.e. filter_by is not set.

Metadata

Typsense Version: "typesense": "^0.7.0" "typesense-instantsearch-adapter": "0.3.0" algoliasearch/3.32.0/algoliasearchLite.min.js npm/instantsearch.js@4.5.0

OS: Win10

jasonbosco commented 3 years ago

@arminus The reason this happens is because filter_by is managed by InstantSearch.js - the parameter is overridden and set automatically by InstantSearch.js when you use one of the widgets like refinementList. Are you able to use those filter widgets?

Another option is to use the configure widget. For example, you can configure a default filter to be attached to all queries like this:

configure({
  facetFilters: ['type:f']
})
arminus commented 3 years ago

Thanks, the configure widget helps. I guess the comment in the demo file could be updated to reflect this, though.

Now I'm stuck on how to set the facetFilters dynamically, I understand I need a custom widget for that but so far I fail to combine that with the pre-built widgets, different topic though...

jasonbosco commented 3 years ago

Zooming out a bit, could you describe the Search UI you're trying to build? I can then help give you ideas on a couple of ways to implement it.

On a side note, here's a more complete example showing several widgets in action: https://github.com/typesense/showcase-songs-search

arminus commented 3 years ago

Thanks a lot, I'll check this out.

For now, I think I'm kind of faster writing my own frontend rather than trying to understand the ins and outs of all the modules involved here... Regardless, I think the comment in https://github.com/typesense/typesense-instantsearch-demo/blob/master/src/app.js line 17 is kind of misleading and could be improved.

jasonbosco commented 3 years ago

I've updated the comment in that file to clarify that filterBy is overriden by InstantSearch.js and suggestions for how to set it.