-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
Using filter_by and other Typesense search parameters #17
Comments
@furnnl The reason filterBy doesn't work when set in And specifically for filters, you want to use the So in your example, you want to do something like this:
Does that help? |
Closing this for now, but please feel free to re-open if you're still running into issues. |
Adding additional info for any react users: const facetFilters = useMemo(() => [`myfilter:0`], [])
// ...
<Configure facetFilters={facetFilters} /> does the trick (making sure to keep the identity of that |
I don't know if it's worth re-opening this but in my tests, adding a correctly-formatted facet filter to /shrug |
@ctorgalson Could you post the full Could you also copy-as-curl the request that gets made to the Typesense server from the browser and post it? |
@jasonbosco I will, though I'll have to recreate the issue as I found an alternate solution :) Adding to this thread because I didn't find it on my first ten trips through Algolia's docs: Virtual Widgets. TL;DR: There's a way in React to provide default values without adding a "real" widget, like this (though <VirtualRefinementList attribute="categories" defaultRefinement="Cell Phones" /> |
Has anyone solved it for vue-instantsearch? If I do: |
@reinoldus Filters need to be specified in the format mentioned here. The adapter then converts them to the Typesense filter string format internally.
This is expected behavior for the configure widget. It's only meant to set a default filter on load. If you need to enforce a filter for all searches, then you want to use the helper object that's exposed via the search function. |
Hi @jasonbosco , I have tried to use the search helper you mentioned which gets injected into the searchFunction as described here. Now I want to add a default filter to all searches based on a language field we have in our typesense index so the user only sees english or german or french results. The field in the index is defined as a facet but when I try to use for example this code: searchFunction(helper) {
helper.addFacetRefinement("language", "de").search();
}, I get the error that the facet 'language' is not defined. It is mentioned that these facets need to be declared when initializing the helper like so: var helper = AlgoliasearchHelper(client, indexName, {
facets: ['nameOfTheAttribute']
}); Is there a way to use facets like that at all using the helper object? I am not sure how I can get to this using the vue version of the adapter and the instansearch-js widget set for vue. |
@krisimmig I just tried this out myself in Vue and I saw the same error you saw: "Error: X is not defined in the facets attribute of the helper configuration". Didn't find anything useful googling around. I was almost going to give up, but by some trial-and-error serendipity I found a configuration that made that error go away:
Here's the full diff to get static filters working in my demo Vue app: typesense/typesense-vue-instantsearch-demo@typesense:c4d2400...typesense:7edf1bf |
That´s it, awesome! :) I didn't think to find the facets param in the Note: After testing this a bit more, we noticed that the load-more is not working anymore when adding facets to all searches. Not sure what is going on but we didn't have any more time to find the cause for this. |
@jasonbosco Thanks for all the tips, this has been driving me insane for days. Can you think of a way to conditionally apply the filterBy logic if a given input has a value in it? Use case is being able to filter by an exact record ID should the user want to do that. |
@pjatx You could do this outside of the context of the adapter, from the Typesense backend. You can turn off typo tolerance and prefix search for just the record ID field, and add it to the query_by fields may be in the beginning of the list. Then if a user searches for an exact record ID, that will be surfaced first. |
@jasonbosco thanks that's super helpful - will give it a shot! |
Supported operands, less than is not supported on numeric filter
Even the commented code works, but for numeric filter, less than is not supported. |
The searchFunction should be placed inside the functions block in vue js. It still works where its placed but if you have a variable, its changeable once its in the methods block._ |
You want to call typesense/typesense-vue-instantsearch-demo@0b30a5b Side note: instantsearch only issues Separately, good call out on moving |
@jasonbosco any way to have a separate search field that only filters on a single attribute within the context of the search adapter? Still wrestling with the same use case above. More context:
Any way this is achievable in my current setup? |
@pjatx Any particular reason you want a separate search box just to search for Film ID? You could use the same search box, and turn off Here's more info on these two params: https://typesense.org/docs/0.21.0/api/documents.html#arguments |
@jasonbosco it's more of a client request, but if I can get it working well in a single search field that should work! This seems to be working:
Does that only constrain the numTypos param to the first field? Tried the following and couldn't get it to work:
|
@pjatx I see, if you really wanted to, you can have multiple search boxes, you'd need multiple instances of InstantSearch as described here.
|
@jasonbosco thanks, that's definitely helpful. Yeah no problem, here's the error I get when I try to pass a string of comma-separated values:
Would be happy to open a separate issue if helpful! |
Could you make sure you're running the latest version of Typesense If you're already running v0.21.0, then this sounds like a bug. Could you open a separate issue? |
@jasonbosco ah - that's it. I'm still on 0.19.0. Will upgrade and let you know if I have any more issues. Can't thank you enough for the help! Love Typesense : ) |
So, we only can filter by field that has beed declared "facet"? In my case, user want to filter by some value that I didnot make it as facet when creating the collection. So, do I need to recreated the collection and import all the data? I didn't find any "edit schema" menu. |
In Typesense Server, you can filter by fields that are not set as facets. However, (unfortunately) InstantSearch.js's widgets makes the assumption that all filter fields are set as facets, since that's how Algolia works. So if you're using InstantSearch with Typesense, you would also have to set any fields you want to filter by as a facet.
Correct. I'd recommend using collection aliases to do this with zero downtime. We have an open item to add support for editing an existing schema: typesense/typesense#96 |
For those trying to configure Angular ~12, here's a working example. component.ts
component.html
|
Further insight for filtering with numbers within Angular:
|
Quick update: I just added the ability for the adapter to handle the |
@jasonbosco came here via a Slack Typesense thread. I just gave Which is weird because I'm passing an array to
I was basing the above implementation off of this example https://www.algolia.com/doc/api-reference/api-parameters/numericFilters/#apply-numeric-filters-on-a-search-query At least, with this adapter version, I can at least get away with using
Am I missing something obvious in the numericFilters implementation? Edit: hmm, is the regex missing a match for the |
this was really helpful in figuring out how to use typesense search parameters with facetWidget = instantsearch.widgets.configure({
facets: ['your facet column']
})
searchInstance = instantsearch({indexName, typesenseSearchClient})
searchInstance.addWidget(facetWidget)
searchInstance.start()
searchInstance.helper.addFacetRefinement('facet column name', 'facet value')) |
Hi @jasonbosco , Is there a way to do this with negation? For example we want to show all items EXCEPT those that have Thanks.
|
@braincomb Does |
Thanks @jasonbosco, that worked perfectly. For anyone looking for the same solution, here's what I did for <ais-instant-search index-name="index" :search-client="searchClient" :search-function="searchHelper"> <ais-configure :facets="['facetToExclude']"></ais-configure> const searchHelper= (helper: any) => {
helper.addFacetExclusion("facetToExclude", "value").search();
}; |
Description
As the documentation says, it should be possible to specify additional search parameters. queryBy works, but filterBy doesn’t.
Steps to reproduce
I tried the following parameters:
additionalSearchParameters: {
queryBy: 'name',
filterBy: 'myfilter:0',
'filter_by': 'myfilter:0',
}
Expected Behavior
Filtered results
Actual Behavior
Unfiltered results
Metadata
Typsense Version:
OS:
The text was updated successfully, but these errors were encountered: