Sha256: 1b61394b6fbe1067cdc362664482e7605d34fda9cddb624d84e6098db54bf1ad

Contents?: true

Size: 627 Bytes

Versions: 4

Compression:

Stored size: 627 Bytes

Contents

module ActiveLucene
  class Query

    def self.for(param)
      if param.instance_of? Hash
        for_attributes param
      elsif param.instance_of? Symbol
        MatchAllDocsQuery.new
      else
        for_string param
      end
    end

    private

    def self.for_attributes(attributes)
      returning BooleanQuery.new do |query|
        attributes.each do |key, value|
          query.add WildcardQuery.new(ActiveLucene::Term.for(key, value)), BooleanClause::Occur::MUST
        end
      end
    end

    def self.for_string(string)
      StandardQueryParser.new(Analyzer.new).parse(string, ALL)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
active_lucene-0.6 lib/active_lucene/query.rb
active_lucene-0.5.2 lib/active_lucene/query.rb
active_lucene-0.5.1 lib/active_lucene/query.rb
active_lucene-0.5.0 lib/active_lucene/query.rb