Skip to content

Commit

Permalink
adding support for punctuation in wildcard matching
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Jul 7, 2009
1 parent 8bddfed commit 381633d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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 })
Expand Down
4 changes: 2 additions & 2 deletions lib/xapit/query_parsers/abstract_query_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions spec/xapit/query_parsers/abstract_query_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.