Class: ParsingNesting::Tree::List
- Defined in:
- lib/parsing_nesting/tree.rb
Instance Attribute Summary collapse
-
#list ⇒ Object
Returns the value of attribute list.
-
#query_parser ⇒ Object
readonly
Returns the value of attribute query_parser.
Instance Method Summary collapse
- #can_embed? ⇒ Boolean
-
#initialize(aList, query_parser) ⇒ List
constructor
A new instance of List.
- #negate ⇒ Object
- #simple_pure_negative? ⇒ Boolean
- #to_query(solr_params = {}) ⇒ Object
-
#to_single_query_params(solr_local_params) ⇒ Object
Returns a Hash, assumes this will be the ONLY :q, used for parsing ‘simple search’ to Solr.
Constructor Details
#initialize(aList, query_parser) ⇒ List
Returns a new instance of List.
135 136 137 138 |
# File 'lib/parsing_nesting/tree.rb', line 135 def initialize(aList, query_parser) @query_parser = query_parser self.list = aList end |
Instance Attribute Details
#list ⇒ Object
Returns the value of attribute list.
133 134 135 |
# File 'lib/parsing_nesting/tree.rb', line 133 def list @list end |
#query_parser ⇒ Object (readonly)
Returns the value of attribute query_parser.
134 135 136 |
# File 'lib/parsing_nesting/tree.rb', line 134 def query_parser @query_parser end |
Instance Method Details
#can_embed? ⇒ Boolean
140 141 142 |
# File 'lib/parsing_nesting/tree.rb', line 140 def false end |
#negate ⇒ Object
198 199 200 |
# File 'lib/parsing_nesting/tree.rb', line 198 def negate List.new(list.collect { |i| i.negate }) end |
#simple_pure_negative? ⇒ Boolean
144 145 146 |
# 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 = {}) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/parsing_nesting/tree.rb', line 148 def to_query(solr_params = {}) queries = [] (, gen_full_query) = list.partition { |i| i.respond_to?(:can_embed?) && i. } unless .empty? queries << build_nested_query(, 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) ⇒ Object
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.
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# 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. }.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 |