Skip to content

Commit

Permalink
don't do wildcard query for single letter terms
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Jun 26, 2009
1 parent 1717eda commit f0f077f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions features/finding.feature
Expand Up @@ -100,3 +100,12 @@ Scenario: Query partial match in keywords
| Jack | Striker |
When I query for "Ja*"
Then I should find records named "John, Jack"

Scenario: Query no partial match in keywords with one letter
Given the following indexed records
| name | sirname |
| John | Jacobson |
| Bill | Niel |
| Jack | J |
When I query for " J*"
Then I should find records named "Jack"
6 changes: 5 additions & 1 deletion lib/xapit/query_parsers/classic_query_parser.rb
@@ -1,13 +1,17 @@
module Xapit
class ClassicQueryParser < AbstractQueryParser
def xapian_query_from_text(text)
xapian_parser.parse_query(text, Xapian::QueryParser::FLAG_WILDCARD | Xapian::QueryParser::FLAG_PHRASE | Xapian::QueryParser::FLAG_BOOLEAN | Xapian::QueryParser::FLAG_LOVEHATE)
xapian_parser.parse_query(cleanup_text(text), Xapian::QueryParser::FLAG_WILDCARD | Xapian::QueryParser::FLAG_PHRASE | Xapian::QueryParser::FLAG_BOOLEAN | Xapian::QueryParser::FLAG_LOVEHATE)
end

def xapian_parser
@xapian_parser ||= build_xapian_parser
end

def cleanup_text(text)
text.gsub(/\b([a-z])\*/i) { $1 }
end

def build_xapian_parser
parser = Xapian::QueryParser.new
parser.database = Config.database
Expand Down
4 changes: 4 additions & 0 deletions spec/xapit/query_parsers/classic_query_parser_spec.rb
Expand Up @@ -13,4 +13,8 @@
expected.default_op = Xapian::Query::OP_AND
@parser.xapian_query_from_text("foo bar").description.should == expected.parse_query("foo bar").description
end

it "should remove asterisks from terms with one letter" do
@parser.cleanup_text("J*").should == "J"
end
end

0 comments on commit f0f077f

Please sign in to comment.