class List

Attributes

list[RW]
query_parser[R]

Public Class Methods

new(aList, query_parser) click to toggle source
# File lib/parsing_nesting/tree.rb, line 135
def initialize(aList, query_parser)
  @query_parser = query_parser
  self.list = aList
end

Public Instance Methods

can_embed?() click to toggle source
# File lib/parsing_nesting/tree.rb, line 140
def can_embed?
  false
end
negate() click to toggle source
# File lib/parsing_nesting/tree.rb, line 198
def negate
  List.new(list.collect { |i| i.negate })
end
simple_pure_negative?() click to toggle source
# File lib/parsing_nesting/tree.rb, line 144
def simple_pure_negative?
  list.find_all { |i| i.is_a? ExcludedClause }.length == list.length
end
to_query(solr_params = {}) click to toggle source
# File lib/parsing_nesting/tree.rb, line 148
def to_query(solr_params = {})
  queries = []

  (embeddable, gen_full_query) = list.partition { |i| i.respond_to?(:can_embed?) && i.can_embed? }

  unless embeddable.empty?
    queries << build_nested_query(embeddable, solr_params, force_deftype: query_parser)
  end

  gen_full_query.each do |node|
    queries << node.to_query(solr_params)
  end

  queries.join(" AND ")
end
to_single_query_params(solr_local_params) click to toggle source

Returns a Hash, assumes this will be the ONLY :q, used for parsing 'simple search' to Solr. Pass in params that need to be LOCAL solr params (using “{foo=bar}” embedded in query). Params that should be sent to Solr seperately are caller's responsibility, merge em into the returned hash.

For very simple queries, this will produce an ordinary Solr q much like would be produced ordinarily. But for AND/OR/NOT, will sometimes include multiple nested queries instead.

This method will still sometimes return a single nested query, that could theoretically really be ordinary query possibly with localparams. It still works, but isn't optimizing for a simpler query, because it's using much of the same code used for combining multiple fields that need nested queries. Maybe we'll optimize later, but the code gets tricky.

# File lib/parsing_nesting/tree.rb, line 180
def to_single_query_params(solr_local_params)
  # Can it be expressed in a single dismax?

  if list.find_all { |i| i.respond_to?(:can_embed?) && i.can_embed? }.length == list.length
    {
      # build_local_params(solr_local_params, nil) + list.collect {|n| n.to_embed}.join(" "),
      :q => build_nested_query(list, solr_local_params, :always_nested => false, :force_deftype => nil),
      :defType => query_parser
    }
  else
    # Can't be expressed in a single dismax, do it the normal way
    {
      :q => self.to_query(solr_local_params),
      :defType => "lucene"
    }
  end
end