Skip to content

Commit

Permalink
Merge pull request #488 from rywall/edismax
Browse files Browse the repository at this point in the history
Fix dismax tests that were broken in #487.
  • Loading branch information
njakobsen committed Oct 25, 2013
2 parents cd6c57e + febcd42 commit 0b959e1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ end

Solr allows searching for phrases: search terms that are close together.

In the default query parser used by Sunspot (dismax), phrase searches
In the default query parser used by Sunspot (edismax), phrase searches
are represented as a double quoted group of words.

```ruby
Expand Down
8 changes: 4 additions & 4 deletions sunspot/spec/api/query/fulltext_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
search do
keywords ''
end
connection.should_not have_last_search_with(:defType => 'dismax')
connection.should_not have_last_search_with(:defType => 'edismax')
end

it 'ignores keywords if nil' do
search do
keywords nil
end
connection.should_not have_last_search_with(:defType => 'dismax')
connection.should_not have_last_search_with(:defType => 'edismax')
end

it 'ignores keywords with only whitespace' do
search do
keywords " \t"
end
connection.should_not have_last_search_with(:defType => 'dismax')
connection.should_not have_last_search_with(:defType => 'edismax')
end

it 'gracefully ignores keywords block if keywords ignored' do
Expand All @@ -37,7 +37,7 @@
search do
keywords 'keyword search'
end
connection.should have_last_search_with(:defType => 'dismax')
connection.should have_last_search_with(:defType => 'edismax')
end

it 'searches types in filter query if keywords used' do
Expand Down
8 changes: 4 additions & 4 deletions sunspot/spec/api/query/geo_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
fulltext 'pizza', :fields => :title
with(:coordinates).near(40.7, -73.5)
end
expected =
"{!dismax fl='* score' qf='title_text'}pizza (#{build_geo_query})"
expected =
"{!edismax fl='* score' qf='title_text'}pizza (#{build_geo_query})"
connection.should have_last_search_including(
:q,
%Q(_query_:"{!dismax qf='title_text'}pizza" (#{build_geo_query}))
%Q(_query_:"{!edismax qf='title_text'}pizza" (#{build_geo_query}))
)
end

Expand All @@ -57,7 +57,7 @@ def build_geo_query(options = {})
boost = options[:boost] || 1.0
hash = 'dr5xx3nytvgs'
(precision..12).map do |i|
phrase =
phrase =
if i == 12 then hash
else "#{hash[0, i]}*"
end
Expand Down
2 changes: 1 addition & 1 deletion sunspot/spec/helpers/query_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def get_filter_tag(boolean_query)
def subqueries(param)
q = connection.searches.last[:q]
subqueries = []
subqueries = q.scan(%r(_query_:"\{!dismax (.*?)\}(.*?)"))
subqueries = q.scan(%r(_query_:"\{!edismax (.*?)\}(.*?)"))
subqueries.map do |subquery|
params = {}
subquery[0].scan(%r((\S+?)='(.+?)')) do |key, value|
Expand Down
28 changes: 28 additions & 0 deletions sunspot/spec/integration/keyword_search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,34 @@
Sunspot.index!(@comment)
end

context 'edismax' do
it 'matches with wildcards' do
results = Sunspot.search(Post) { keywords '*oas*' }.results
[0,2].each { |i| results.should include(@posts[i])}
[1].each { |i| results.should_not include(@posts[i])}
end

it 'matches multiple keywords on different fields with wildcards using subqueries' do
results = Sunspot.search(Post) do
keywords 'insuffic*',:fields=>[:title]
keywords 'win*',:fields=>[:body]
end.results
[0].each {|i| results.should include(@posts[i])}
[1,2].each {|i| results.should_not include(@posts[i])}
end

it 'matches with proximity' do
results = Sunspot.search(Post) { keywords '"wind buffer"~4' }.results
[0,1].each {|i| results.should_not include(@posts[i])}
[2].each {|i| results.should include(@posts[i])}
end

it 'does not match if not within proximity' do
results = Sunspot.search(Post) { keywords '"wind buffer"~1' }.results
results.should == []
end
end

it 'matches a single keyword out of a single field' do
results = Sunspot.search(Post) { keywords 'toast' }.results
[0, 2].each { |i| results.should include(@posts[i]) }
Expand Down
8 changes: 4 additions & 4 deletions sunspot_rails/lib/sunspot/rails/log_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ def self.reset_runtime
rt, self.runtime = runtime, 0
rt
end

def self.logger=(logger)
@logger = logger
end

def self.logger
@logger if defined?(@logger)
end

def logger
self.class.logger || ::Rails.logger
end
Expand All @@ -32,7 +32,7 @@ def request(event)

name = '%s (%.1fms)' % ["SOLR Request", event.duration]

# produces: path=select parameters={fq: ["type:Tag"], q: "rossi", fl: "* score", qf: "tag_name_text", defType: "dismax", start: 0, rows: 20}
# produces: path=select parameters={fq: ["type:Tag"], q: "rossi", fl: "* score", qf: "tag_name_text", defType: "edismax", start: 0, rows: 20}
path = color(event.payload[:path], BOLD, true)
parameters = event.payload[:parameters].map { |k, v|
v = "\"#{v}\"" if v.is_a? String
Expand Down

0 comments on commit 0b959e1

Please sign in to comment.