require 'spec_helper'
describe "Sphinx Excepts", :live => true do
before :each do
@client = Riddle::Client.new("localhost", 9313)
end
it "should highlight a single word multiple times in a document" do
@client.excerpts(
:index => "people",
:words => "Mary",
:docs => ["Mary, Mary, quite contrary."]
).should == [
'Mary, Mary, quite contrary.'
]
end
it "should use specified word markers" do
@client.excerpts(
:index => "people",
:words => "Mary",
:docs => ["Mary, Mary, quite contrary."],
:before_match => "",
:after_match => ""
).should == [
"Mary, Mary, quite contrary."
]
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 => "",
:after_match => ""
)
case Riddle.loaded_version
when '0.9.9'
excerpts.should == [
<<-SENTENCE
This is a really long sentence written by Pat. 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: Pat.
SENTENCE
]
when '1.10'
excerpts.should == [" … really long sentence written by Pat. It has to be over … . This keyword, however, is\nnot. It's just my name: Pat … "]
when '2.0.1', '2.1.0'
excerpts.should == [" … really long sentence written by Pat. It has to be over … . It's just my name: Pat.\n"]
else
excerpts.should == [
<<-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? … interested in finding out,
yeah? Excerpts are particularly riveting. This keyword, however, is
not. It's just my name: Pat.
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 => "",
:after_match => "",
:chunk_separator => " --- "
)
case Riddle.loaded_version
when '0.9.9'
excerpts.should == [
<<-SENTENCE
This is a really long sentence written by Pat. 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: Pat.
SENTENCE
]
when '1.10'
excerpts.should == [" --- really long sentence written by Pat. It has to be over --- . This keyword, however, is\nnot. It's just my name: Pat --- "]
when '2.0.1', '2.1.0'
excerpts.should == [" --- really long sentence written by Pat. It has to be over --- . It's just my name: Pat.\n"]
else
excerpts.should == [
<<-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? --- interested in finding out,
yeah? Excerpts are particularly riveting. This keyword, however, is
not. It's just my name: Pat.
SENTENCE
]
end
end
it "should return multiple results for multiple documents" do
@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 => "",
:after_match => ""
).should == [
"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"
]
end
end