You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I have a text field, let's say title.
Sometimes I need to search for this field with a fulltext search which it works.
Other times I need to search by exact match but it doesn't work (it works for string type tho).
I tried with:
but it return records with a partial match, not the exact match (i.e. I search for test but it returns all documents with title testsomething).
So I ended up indexing the field with two different names and type (string and text).
What I am doing wrong?
The text was updated successfully, but these errors were encountered:
You have to create a separate search field for the exact match scenario.
class Article < ApplicationRecord
searchable do
text :title
string :title_str
end
def title_str
title
end
end
Article.search do
with(:title_str, params[:exact]) if params[:exact].present?
fulltext params[:q] if params[:q].present?
end
Hi,
I have a text field, let's say
title
.Sometimes I need to search for this field with a fulltext search which it works.
Other times I need to search by exact match but it doesn't work (it works for
string
type tho).I tried with:
but it return records with a partial match, not the exact match (i.e. I search for
test
but it returns all documents with titletestsomething
).So I ended up indexing the field with two different names and type (
string
andtext
).What I am doing wrong?
The text was updated successfully, but these errors were encountered: