aboutsummaryrefslogtreecommitdiffstats
path: root/spec/integration/xapian_search_highlighting_spec.rb
blob: 65a34cf91c662618fa3424c2f26d3eedb7dff282 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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

    it 'highlights stemmed words even if the stem is unhelpful' do
        # Stemming returns 'bore' as the word to highlight which can't be
        # matched in the original phrase.
        phrase = 'boring'
        search = ActsAsXapian::Search.new([PublicBody], phrase, :limit => 1)
        matches = search.words_to_highlight(:regex => true, :include_original => true)

        highlight_matches(phrase, matches).should == '<mark>boring</mark>'
    end

end