Class: EasySolr::Expressions
- Inherits:
-
Object
- Object
- EasySolr::Expressions
- Defined in:
- lib/easy_solr/expressions.rb
Instance Attribute Summary collapse
-
#nn_custom_links ⇒ Object
Returns the value of attribute nn_custom_links.
Instance Method Summary collapse
-
#destroy! ⇒ Object
Description.
-
#initialize ⇒ Expressions
constructor
A new instance of Expressions.
-
#query_string_for_solr ⇒ Object
Description.
-
#solr_where(prefix, *params) ⇒ Object
Description.
Constructor Details
#initialize ⇒ Expressions
Returns a new instance of Expressions.
6 7 8 9 10 11 |
# File 'lib/easy_solr/expressions.rb', line 6 def initialize @nn_solr_query_string = ' ' @nn_prefix_expression = [] @nn_params_array = [] @nn_query_string = '' end |
Instance Attribute Details
#nn_custom_links ⇒ Object
Returns the value of attribute nn_custom_links.
4 5 6 |
# File 'lib/easy_solr/expressions.rb', line 4 def nn_custom_links @nn_custom_links end |
Instance Method Details
#destroy! ⇒ Object
Description
每一次查询之后, 清除全部的 传入参数
61 62 63 64 65 66 |
# File 'lib/easy_solr/expressions.rb', line 61 def destroy! @nn_solr_query_string = ' ' @nn_prefix_expression = [] @nn_params_array = [] @nn_query_string = '' end |
#query_string_for_solr ⇒ Object
Description
生成 Solr 可以解析的字符串
Return
例如,将solr_params = expr.solr_where(“ title = ? and id = ? ”, ‘奥迪’, ‘620460’).
solr_where(" second_editor_id = ? ", '138')
生成
title: 奥迪 id: 620460 second_editor_id: 138
46 47 48 49 50 51 52 53 54 |
# File 'lib/easy_solr/expressions.rb', line 46 def query_string_for_solr the_whole_solr_query_string = ' ' @nn_prefix_expression.each do |_query_item| the_whole_solr_query_string.concat(_query_item.traslate_to_solr_str) end the_whole_solr_query_string end |
#solr_where(prefix, *params) ⇒ Object
Description
拼接用户传递的参数,将其转换为Solr可以识别的字符串
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/easy_solr/expressions.rb', line 19 def solr_where(prefix, *params) prefix_array = prefix.split("and") params.each_with_index do |_key, _index| @nn_prefix_expression << \ ::EasySolr::QueryItem.new(nn_custom_links, prefix_array[_index], _key) end self end |