Sha256: 0be9de4a4832eeea861c067df72af106a2cc3ae51a07ddd958b3fb929b6566ef

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

# encoding: utf-8

# Parse a query expression and convert it to Xapian Query arguments
# @author Gernot Kogler

module XapianDb
  
  class QueryParser
    
    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
      @query_flags |= Xapian::QueryParser::FLAG_BOOLEAN_ANY_CASE
    end
    
    def parse(expression)
      parser            = Xapian::QueryParser.new
      parser.database   = @db.reader
      parser.default_op = Xapian::Query::OP_AND # Could be made configurable
      # TODO: Setup stopper, stemmer, defaults and fields
      
      # 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}") }
      parser.parse_query(expression, @query_flags)
    end
    
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xapian_db-0.3.1 lib/xapian_db/query_parser.rb