Class: ChefZero::Solr::Query::RegexpableQuery
- Inherits:
-
Object
- Object
- ChefZero::Solr::Query::RegexpableQuery
- Defined in:
- lib/chef_zero/solr/query/regexpable_query.rb
Constant Summary collapse
- DEFAULT_FIELD =
"text".freeze
- WORD_CHARACTER =
"[A-Za-z0-9@._':\-]".freeze
- NON_WORD_CHARACTER =
"[^A-Za-z0-9@._':\-]".freeze
Instance Attribute Summary collapse
-
#literal_string ⇒ Object
readonly
Returns the value of attribute literal_string.
-
#regexp ⇒ Object
readonly
Returns the value of attribute regexp.
-
#regexp_string ⇒ Object
readonly
Returns the value of attribute regexp_string.
Instance Method Summary collapse
-
#initialize(regexp_string, literal_string) ⇒ RegexpableQuery
constructor
A new instance of RegexpableQuery.
- #matches_doc?(doc) ⇒ Boolean
- #matches_values?(values) ⇒ Boolean
Constructor Details
#initialize(regexp_string, literal_string) ⇒ RegexpableQuery
Returns a new instance of RegexpableQuery.
5 6 7 8 9 10 |
# File 'lib/chef_zero/solr/query/regexpable_query.rb', line 5 def initialize(regexp_string, literal_string) @regexp_string = regexp_string # Surround the regexp with word boundaries @regexp = Regexp.new("(^|#{NON_WORD_CHARACTER})#{regexp_string}($|#{NON_WORD_CHARACTER})", true) @literal_string = literal_string end |
Instance Attribute Details
#literal_string ⇒ Object (readonly)
Returns the value of attribute literal_string.
12 13 14 |
# File 'lib/chef_zero/solr/query/regexpable_query.rb', line 12 def literal_string @literal_string end |
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
14 15 16 |
# File 'lib/chef_zero/solr/query/regexpable_query.rb', line 14 def regexp @regexp end |
#regexp_string ⇒ Object (readonly)
Returns the value of attribute regexp_string.
13 14 15 |
# File 'lib/chef_zero/solr/query/regexpable_query.rb', line 13 def regexp_string @regexp_string end |
Instance Method Details
#matches_doc?(doc) ⇒ Boolean
16 17 18 |
# File 'lib/chef_zero/solr/query/regexpable_query.rb', line 16 def matches_doc?(doc) matches_values?(doc[DEFAULT_FIELD]) end |
#matches_values?(values) ⇒ Boolean
20 21 22 |
# File 'lib/chef_zero/solr/query/regexpable_query.rb', line 20 def matches_values?(values) values.any? { |value| !@regexp.match(value).nil? } end |