diff options
author | Gareth Rees <gareth@mysociety.org> | 2014-05-30 12:42:48 +0100 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2014-06-25 10:40:37 +0100 |
commit | e5a73815f580d296572e11b71b5f3ed320bbe912 (patch) | |
tree | a6afe88e876933f15a65e9f948e195dc5b79cf5e /spec/integration | |
parent | b429a1a2fc2a3b73322e6361fb27ed0a5c3ace7f (diff) |
Add helper to highlight and excerpt by regex
Backport of https://github.com/rails/rails/pull/11793/
Contains integration tests to check that it works
as expected with ActsAsXapian.
Diffstat (limited to 'spec/integration')
-rw-r--r-- | spec/integration/xapian_search_highlighting_spec.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/integration/xapian_search_highlighting_spec.rb b/spec/integration/xapian_search_highlighting_spec.rb new file mode 100644 index 000000000..7bd64c995 --- /dev/null +++ b/spec/integration/xapian_search_highlighting_spec.rb @@ -0,0 +1,29 @@ +require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') + +describe 'highlighting search results' do + include HighlightHelper + + it 'ignores stopwords' do + phrase = 'department of humpadinking' + search = ActsAsXapian::Search.new([PublicBody], phrase, :limit => 1) + matches = search.words_to_highlight(:regex => true) + highlight_matches(phrase, matches).should == '<mark>department</mark> of <mark>humpadinking</mark>' + end + + it 'ignores case' do + search_phrase = 'department of humpadinking' + search = ActsAsXapian::Search.new([PublicBody], search_phrase, :limit => 1) + matches = search.words_to_highlight(:regex => true) + highlight_matches('Department of Humpadinking', matches).should == '<mark>Department</mark> of <mark>Humpadinking</mark>' + end + + it 'highlights stemmed words' do + phrase = 'department' + search = ActsAsXapian::Search.new([PublicBody], phrase, :limit => 1) + matches = search.words_to_highlight(:regex => true) + + search.words_to_highlight(:regex => false).should == ['depart'] + highlight_matches(phrase, matches).should == '<mark>department</mark>' + end + +end |