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

Issue with indexing when sanitizing attributes #323

Open
joshio1 opened this issue Feb 10, 2024 · 1 comment
Open

Issue with indexing when sanitizing attributes #323

joshio1 opened this issue Feb 10, 2024 · 1 comment
Labels
support Issues related to support questions.

Comments

@joshio1
Copy link

joshio1 commented Feb 10, 2024

Description
When I use sanitize attributes, search does not return expected results. For eg. I have:

class Book
   meilisearch sanitize: true do
     attribute :title, :description
  end
end

This is only for book with description which has some HTML in this format:

book = create(:book, description: "<div>Hello</div><div>Hi</div>")

Now, when I search like this:

[3] pry(#<RSpec::ExampleGroups::Library>)> Book.raw_search('Hi')
=> {"hits"=>[],
 "query"=>"Hi",
 "processingTimeMs"=>0,
 "limit"=>20,
 "offset"=>0,
 "estimatedTotalHits"=>0,
 "nbHits"=>0}

Expected behavior
I was expecting to get 1 hit for the word Hi.

Current behavior
But I get 0 hits for Hi. I get 1 hit if we search Hello instead and also if book is created using this description: <div>Hello</div><div> Hi</div> (i.e. one space before Hi)

Environment (please complete the following information):

  • OS: Mac
  • Meilisearch server version: 1.4.2
  • meilisearch-rails version: 0.10.1
  • Rails version: 7.1.1
@ellnix
Copy link
Collaborator

ellnix commented Feb 12, 2024

The sanitize_attributes option will completely remove any html tags from attributes before sending it to meilisearch. So while when you search for the book you will see [#<Book id: 1, description: "<div>Hello</div><div>Hi</div>"..., in the meilisearch server it will be saved as {"description": "HelloHi"....

Therefore you are searching for Hi in HelloHi which does not return any results because meilisearch is a prefix based search engine, and does not return results that match within a word.

Here's an issue in the meilisearch server repo where someone else ran across this: meilisearch/meilisearch#3863.

Let me know if that explanation makes sense, I will leave the issue open just in case.

@curquiza curquiza added the support Issues related to support questions. label Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Issues related to support questions.
Projects
None yet
Development

No branches or pull requests

3 participants