Sha256: ddc108963fb993876d90dd6cacf179bc048150d84c442eb828dbed03d9657327
Contents?: true
Size: 1.75 KB
Versions: 1
Compression:
Stored size: 1.75 KB
Contents
# encoding: utf-8 module XapianDb # Parse a query expression and create a xapian query object # @author Gernot Kogler class QueryParser # The spelling corrected query (if a language is configured) # @return [String] attr_reader :corrected_query # Constructor # @param [XapianDb::Database] database The database to query def initialize(database) @db = database # Set the parser options @query_flags = 0 @query_flags |= Xapian::QueryParser::FLAG_WILDCARD # enable wildcards @query_flags |= Xapian::QueryParser::FLAG_BOOLEAN # enable boolean operators @query_flags |= Xapian::QueryParser::FLAG_BOOLEAN_ANY_CASE # enable case insensitive boolean operators @query_flags |= Xapian::QueryParser::FLAG_SPELLING_CORRECTION # enable spelling corrections end # Parse an expression # @return [Xapian::Query] The query object (see http://xapian.org/docs/apidoc/html/classXapian_1_1Query.html) def parse(expression) parser = Xapian::QueryParser.new parser.database = @db.reader parser.default_op = Xapian::Query::OP_AND # Could be made configurable if XapianDb::Config.stemmer parser.stemmer = XapianDb::Config.stemmer parser.stemming_strategy = Xapian::QueryParser::STEM_SOME parser.stopper = XapianDb::Config.stopper end # Add the searchable prefixes to allow searches by field # (like "name:Kogler") XapianDb::DocumentBlueprint.searchable_prefixes.each{|prefix| parser.add_prefix(prefix.to_s.downcase, "X#{prefix.to_s.upcase}") } query = parser.parse_query(expression, @query_flags) @corrected_query = parser.get_corrected_query_string query end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
xapian_db-0.3.3 | lib/xapian_db/query_parser.rb |