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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
# frozen_string_literal: true
require 'spec_helper'
describe "Sphinx Excepts", :live => true do
let(:client) { Riddle::Client.new "localhost", 9313 }
let(:controller) do
controller = Riddle::Controller.new nil, ''
controller.bin_path = Sphinx.new.bin_path
controller
end
it "should highlight a single word multiple times in a document" do
excerpts = client.excerpts(
:index => "people",
:words => "Mary",
:docs => ["Mary, Mary, quite contrary."]
)
if controller.sphinx_version.to_i >= 3
excerpts.should == [
'<span class="match">Mary, Mary</span>, quite contrary.'
]
else
excerpts.should == [
'<span class="match">Mary</span>, <span class="match">Mary</span>, quite contrary.'
]
end
end
it "should use specified word markers" do
excerpts = client.excerpts(
:index => "people",
:words => "Mary",
:docs => ["Mary, Mary, quite contrary."],
:before_match => "<em>",
:after_match => "</em>"
)
if controller.sphinx_version.to_i >= 3
excerpts.should == [
"<em>Mary, Mary</em>, quite contrary."
]
else
excerpts.should == [
"<em>Mary</em>, <em>Mary</em>, quite contrary."
]
end
end
it "should separate matches that are far apart by an ellipsis by default" do
excerpts = client.excerpts(
:index => "people",
:words => "Pat",
:docs => [
<<-SENTENCE
This is a really long sentence written by Pat. It has to be over 256
characters long, between keywords. But what is the keyword? Well, I
can't tell you just yet... wait patiently until we've hit the 256 mark.
It'll take a bit longer than you think. We're probably just hitting the
200 mark at this point. But I think we've now arrived - so I can tell
you what the keyword is. I bet you're really interested in finding out,
yeah? Excerpts are particularly riveting. This keyword, however, is
not. It's just my name: Pat.
SENTENCE
],
:before_match => "<em>",
:after_match => "</em>"
)
case Riddle.loaded_version
when '0.9.9'
excerpts.should == [
<<-SENTENCE
This is a really long sentence written by <em>Pat</em>. It has to be over 256
characters long, between keywords. But what is the … 're really interested in finding out,
yeah? Excerpts are particularly riveting. This keyword, however, is
not. It's just my name: <em>Pat</em>.
SENTENCE
]
when '1.10'
excerpts.should == [" … really long sentence written by <em>Pat</em>. It has to be over … . This keyword, however, is\nnot. It's just my name: <em>Pat</em> … "]
when '2.0.1', '2.1.0'
excerpts.should == [" … really long sentence written by <em>Pat</em>. It has to be over … . It's just my name: <em>Pat</em>.\n"]
else
excerpts.should == [
<<-SENTENCE
This is a really long sentence written by <em>Pat</em>. It has to be over 256
characters long, between keywords. But what is the keyword? … interested in finding out,
yeah? Excerpts are particularly riveting. This keyword, however, is
not. It's just my name: <em>Pat</em>.
SENTENCE
]
end
end
it "should use the provided separator" do
excerpts = client.excerpts(
:index => "people",
:words => "Pat",
:docs => [
<<-SENTENCE
This is a really long sentence written by Pat. It has to be over 256
characters long, between keywords. But what is the keyword? Well, I
can't tell you just yet... wait patiently until we've hit the 256 mark.
It'll take a bit longer than you think. We're probably just hitting the
200 mark at this point. But I think we've now arrived - so I can tell
you what the keyword is. I bet you're really interested in finding out,
yeah? Excerpts are particularly riveting. This keyword, however, is
not. It's just my name: Pat.
SENTENCE
],
:before_match => "<em>",
:after_match => "</em>",
:chunk_separator => " --- "
)
case Riddle.loaded_version
when '0.9.9'
excerpts.should == [
<<-SENTENCE
This is a really long sentence written by <em>Pat</em>. It has to be over 256
characters long, between keywords. But what is the --- 're really interested in finding out,
yeah? Excerpts are particularly riveting. This keyword, however, is
not. It's just my name: <em>Pat</em>.
SENTENCE
]
when '1.10'
excerpts.should == [" --- really long sentence written by <em>Pat</em>. It has to be over --- . This keyword, however, is\nnot. It's just my name: <em>Pat</em> --- "]
when '2.0.1', '2.1.0'
excerpts.should == [" --- really long sentence written by <em>Pat</em>. It has to be over --- . It's just my name: <em>Pat</em>.\n"]
else
excerpts.should == [
<<-SENTENCE
This is a really long sentence written by <em>Pat</em>. It has to be over 256
characters long, between keywords. But what is the keyword? --- interested in finding out,
yeah? Excerpts are particularly riveting. This keyword, however, is
not. It's just my name: <em>Pat</em>.
SENTENCE
]
end
end
it "should return multiple results for multiple documents" do
excerpts = client.excerpts(
:index => "people",
:words => "Mary",
:docs => [
"Mary, Mary, quite contrary.",
"The epithet \"Bloody Mary\" is associated with a number of historical and fictional women, most notably Queen Mary I of England"
],
:before_match => "<em>",
:after_match => "</em>"
)
if controller.sphinx_version.to_f >= 3
excerpts.should == [
"<em>Mary, Mary</em>, quite contrary.",
"The epithet \"Bloody <em>Mary</em>\" is associated with a number of historical and fictional women, most notably Queen <em>Mary</em> I of England"
]
else
excerpts.should == [
"<em>Mary</em>, <em>Mary</em>, quite contrary.",
"The epithet \"Bloody <em>Mary</em>\" is associated with a number of historical and fictional women, most notably Queen <em>Mary</em> I of England"
]
end
end
end
|