How do to a 'contains' in a specific attribute

Is there anyway to do a contains style search (hopefully with typo,proximity,exact matching etc scoring) on one specific attribute?

I can see from the docs this can be done ‘exact’ but i cant see anything like this.

Hi Dan,

Thanks for your question!

Indeed it’s not possible to filter on a specific attribute with a contain kind of query while keeping typo, proximity… and all the textual ranking features.

What you are trying to do actually sounds a lot like regular search: having a searchable attribute and typing a keyword which will match for any record that contains it.
Could you clarify or provide an example of what specific issue you want to solve? That would help a lot :slight_smile:

Looking forward to your answer!

Thanks for responding.

For example, if you head a search for books, and you had searchable attributes for title, author, publisher, genre and the content of the book. In addition you have facets for title, author, publisher, genre , but NOT content as this would make no sense.

If I wanted to offer an ‘advance search’ that allowed the user to find all books containing a word, aswell as selecting facets etc, how would I do this in Algolia.

(I know we could create a separate index where only content was a searchable attribute, but this would not allow us to apply other facets).

help !

Hi @d.garnys - you can keep that all in the same index and get both faceting and search of the content. Overall you’re nicely lined up with what Algolia can do.

I’d recommend looking at instantsearch.js or the new React version for building the front end of that experience. There are built in components for the search box and for selecting facets. See the demos to try them in action.

Hey dzello , Sorry if I am being dumb, I don’t understand how this applies to my question, I know about instantsearch.js, its really cool, but there are no example of filtering records via searchable attributes which are not facets?

Ahh okay, I think I’m seeing your question a bit more clearly.

Have a look at the documentation here about filters. In there, you can see examples of numeric filtering by attributes as well as faceting.

Per the above:

If I wanted to offer an ‘advance search’ that allowed the user to find all books containing a word, aswell as selecting facets etc, how would I do this in Algolia.

Unless I’m missing something, I think it’s the way you described it above. All the attributes in one index, with content as a searchable attribute and the other attributes as facets.

Hi @d.garnys

I’ve made a very quick demo showing a rough example of how it might look.
You will see that I can search in the title and the content only, and I can filter with facets defined on author, genre and publisher (displayed on the left). It may not be exactly the settings you want to have but it’s just to give you an idea of how it may look.
Side note: you probably don’t want to facet on the title because it’s a value that will always be different and that doesn’t really add value as a filter.

Have a look on the following GIF. Happy to dig more into your questions if this is not what you are trying to do :slight_smile:

1 Like

Thanks for spending the time to do this Julien !?!?! beyond the call of duty.

I think I am right in saying this means only content is searchable? So i couldn’t do something like, find all books where the title contains ‘foo’ and the content contains ‘bar’?

Glad to do it if it’s helpful :slight_smile:

If you search for “foo bar” and there is an object containing “foo” in the title and “bar” in the content, it will definitely match! However, an object with both words in the same attribute might rank higher depending on the proximity and attribute criteria:

Does it make things clearer?

1 Like