Permalink
Browse files

adding support for punctuation in wildcard matching

  • Loading branch information...
1 parent 8bddfed commit 381633d6430b0c1a04cd7cfebba6911e05732159 @ryanb committed Jul 7, 2009
View
@@ -1,3 +1,7 @@
+* support punctuation in wildcard matching
+
+* fixing nested search calls
+
* chain a separate search with "or_search" to find records matching either one
search("foo").or_search(:conditions => { :priority => 3 })
@@ -165,10 +165,10 @@ def condition_term(name, value)
# Expands the wildcard in the term (just at the end) and returns a query
# which will match any term that starts with the given term.
def wildcard_query(term, prefix = "")
- partial_term = term.sub(/\*$/, '') # remove asterisk at end if it exists
+ full_term = (prefix + term.downcase).sub(/\*$/, '') # remove asterisk at end if it exists
parser = Xapian::QueryParser.new
parser.database = Xapit::Config.database
- parser.parse_query(partial_term, Xapian::QueryParser::FLAG_PARTIAL, prefix)
+ parser.parse_query(full_term[-1..-1], Xapian::QueryParser::FLAG_PARTIAL, full_term[0..-2])
end
end
end
@@ -48,4 +48,13 @@
parser = Xapit::AbstractQueryParser.new(XapitMember, :conditions => { :foo => [2..5, 10] })
parser.condition_terms.first.xapian_query.description.should == expected.description
end
+
+ it "should expand punctuated terms properly" do
+ XapitMember.xapit { |i| i.field :name }
+ bar = XapitMember.new(:name => "foo-bar")
+ baz = XapitMember.new(:name => "foo-baz")
+ zap = XapitMember.new(:name => "foo-zap")
+ Xapit.index_all
+ XapitMember.search(:conditions => { :name => "foo-b*"}).should == [bar, baz]
+ end
end

0 comments on commit 381633d

Please sign in to comment.