aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancis Irving <francis@mysociety.org>2009-12-18 00:37:14 +0000
committerFrancis Irving <francis@mysociety.org>2009-12-18 00:37:14 +0000
commitfcfa755f02f1ccd388566b5b60e7c2ef717cdd7d (patch)
tree22859d0874b69233ac7748023694e059e95bfb11
parentb040ef186664b5d4f8dfcd9e05726016907f31c1 (diff)
Test case for substring bug due to stemming, and fix for it.
-rw-r--r--spec/models/xapian_spec.rb15
-rw-r--r--vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb6
2 files changed, 15 insertions, 6 deletions
diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb
index d4d8b53ae..8b63eb465 100644
--- a/spec/models/xapian_spec.rb
+++ b/spec/models/xapian_spec.rb
@@ -100,12 +100,17 @@ describe User, " when indexing requests by user they are from" do
xapian_object.results[0][:model].should == info_request_events(:silly_comment_event)
end
- it "should not get confused searching for requests when one user has a name which is a substring of another" do
+ it "should not get confused searching for requests when one user has a name which has same stem as another" do
rebuild_xapian_index
- silly_user = users(:silly_name_user)
- silly_user.name = "Bob S"
- silly_user.url_name.should == 'bob_s'
+ bob_smith_user = users(:bob_smith_user)
+ bob_smith_user.name = "John King"
+ bob_smith_user.url_name.should == 'john_king'
+ bob_smith_user.save!
+
+ silly_user = users(:silly_name_user)
+ silly_user.name = "John K"
+ silly_user.url_name.should == 'john_k'
silly_user.save!
naughty_chicken_request = info_requests(:naughty_chicken_request)
@@ -115,7 +120,7 @@ describe User, " when indexing requests by user they are from" do
update_xapian_index
# def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page)
- xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:bob_s", 'created_at', true, 'request_collapse', 100, 1)
+ xapian_object = InfoRequest.full_search([InfoRequestEvent], "requested_by:john_k", 'created_at', true, 'request_collapse', 100, 1)
xapian_object.results.size.should == 1
xapian_object.results[0][:model].should == info_request_events(:silly_outgoing_message_event)
end
diff --git a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb
index 0d0605cd3..269a1be2f 100644
--- a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb
+++ b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb
@@ -166,7 +166,11 @@ module ActsAsXapian
raise "Z is reserved for stemming terms" if term[1] == "Z"
raise "Already have code '" + term[1] + "' in another model but with different prefix '" + @@terms_by_capital[term[1]] + "'" if @@terms_by_capital.include?(term[1]) && @@terms_by_capital[term[1]] != term[2]
@@terms_by_capital[term[1]] = term[2]
- @@query_parser.add_prefix(term[2], term[1])
+ # XXX use boolean here so doesn't stem our URL names in WhatDoTheyKnow
+ # If making acts_as_xapian generic, would really need to make the :terms have
+ # another option that lets people choose non-boolean for terms that need it
+ # (i.e. searching explicitly within a free text field)
+ @@query_parser.add_boolean_prefix(term[2], term[1])
end
end
if options[:values]