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

Fixed highlight problem when a stemming dictionary is configured. #331

Merged
merged 2 commits into from
Jan 16, 2017

Conversation

torce
Copy link
Contributor

@torce torce commented Oct 6, 2016

Hi,
We a re using pg_search with languages and we are notice that the resulting snippets are not wrapped with tags if a dictionary is selected.

I am using pg_search 1.0.6, ruby 2.3.1 and active_record 4.2.4

A minimal script that reproduces the problem:

require 'active_record'
require 'pg_search'

ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.establish_connection(
  adapter: 'postgresql',
  database: 'problem',
  username: 'user',
  password: 'password'
)
unless ActiveRecord::Base.connection.table_exists?(:tests)
  ActiveRecord::Base.connection.create_table :tests do |t|
    t.text :body
  end
end

class Test < ActiveRecord::Base
  include PgSearch

  pg_search_scope :search_es,
                  against: :body,
                  using: {
                    tsearch: {
                      dictionary: 'spanish',
                      highlight: {
                        start_sel: '<b>',
                        stop_sel: '</b>'
                      }
                    },
                  }
  pg_search_scope :search,
                  against: :body,
                  using: {
                    tsearch: {
                      highlight: {
                        start_sel: '<b>',
                        stop_sel: '</b>'
                      }
                    },
                  }
end

Test.create!(body: 'La filosofía occidental ha tenido una profunda influencia y se ha visto profundamente influida por la ciencia, la religión y la política occidentales.')

puts Test.search_es('ciencia').with_pg_search_highlight.first.pg_search_highlight
# => La filosofía occidental ha tenido una profunda influencia y se ha visto profundamente influida por

puts Test.search('ciencia').with_pg_search_highlight.first.pg_search_highlight
# => influencia y se ha visto profundamente influida por la <b>ciencia</b>, la religión y la política occidentales.

In the first case, using the Spanish dictionary, the word 'ciencia' was not wrapped with <b> tags.
If the dictionary option is omitted, pg_search works as expected.

The generated query in the first case omitted the first parameter of ts_headline, so I have fixed this using the default dictionary ('simple') in case of none selected.
Regards.

@torce
Copy link
Contributor Author

torce commented Oct 6, 2016

Sorry, it is a duplicated of #302.
I did not realize that already existed.

@torce torce closed this Oct 6, 2016
@nertzy
Copy link
Collaborator

nertzy commented Dec 21, 2016

@torce if you add a test to this pull request that fails without the change and passes with the change then I will merge it. The other pull request has not supplied a test yet.

@torce
Copy link
Contributor Author

torce commented Dec 22, 2016

I will take a look to your current tests and add a test as soon as possible, but it could take a few days.

@nertzy nertzy merged commit 07426a8 into Casecommons:master Jan 16, 2017
@nertzy nertzy removed the ready label Jan 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants