neo4j-core 0.0.15-java → 2.0.0.alpha.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/Gemfile +2 -2
  2. data/README.rdoc +12 -192
  3. data/lib/neo4j-core.rb +3 -19
  4. data/lib/neo4j-core/database.rb +5 -4
  5. data/lib/neo4j-core/event_handler.rb +1 -1
  6. data/lib/neo4j-core/index/class_methods.rb +41 -27
  7. data/lib/neo4j-core/index/index.rb +4 -3
  8. data/lib/neo4j-core/index/index_config.rb +23 -30
  9. data/lib/neo4j-core/index/indexer.rb +53 -65
  10. data/lib/neo4j-core/index/indexer_registry.rb +2 -2
  11. data/lib/neo4j-core/index/lucene_query.rb +42 -53
  12. data/lib/neo4j-core/node/class_methods.rb +4 -4
  13. data/lib/neo4j-core/node/node.rb +8 -1
  14. data/lib/neo4j-core/property/property.rb +3 -1
  15. data/lib/neo4j-core/relationship/relationship.rb +10 -8
  16. data/lib/neo4j-core/rels/rels.rb +4 -9
  17. data/lib/neo4j-core/rels/traverser.rb +27 -13
  18. data/lib/neo4j-core/traversal/prune_evaluator.rb +2 -2
  19. data/lib/neo4j-core/traversal/traverser.rb +27 -122
  20. data/lib/neo4j-core/type_converters/type_converters.rb +287 -0
  21. data/lib/neo4j-core/version.rb +1 -1
  22. data/lib/neo4j-core/version.rb~ +3 -0
  23. data/lib/neo4j/config.rb +6 -3
  24. data/lib/neo4j/neo4j.rb +22 -51
  25. data/lib/neo4j/node.rb +0 -27
  26. data/lib/neo4j/relationship.rb +0 -25
  27. data/lib/test.rb +27 -0
  28. data/neo4j-core.gemspec +2 -2
  29. metadata +11 -17
  30. data/lib/neo4j-core/cypher/cypher.rb +0 -969
  31. data/lib/neo4j-core/cypher/result_wrapper.rb +0 -48
  32. data/lib/neo4j-core/hash_with_indifferent_access.rb +0 -165
  33. data/lib/neo4j-core/index/unique_factory.rb +0 -54
  34. data/lib/neo4j-core/property/java.rb +0 -59
  35. data/lib/neo4j-core/wrapper/class_methods.rb +0 -22
  36. data/lib/neo4j-core/wrapper/wrapper.rb +0 -20
  37. data/lib/neo4j/algo.rb +0 -300
  38. data/lib/neo4j/cypher.rb +0 -180
@@ -5,25 +5,14 @@ module Neo4j
5
5
  # Responsible for holding the configuration for one index
6
6
  # Is used in a DSL to configure the index.
7
7
  class IndexConfig
8
- attr_reader :_trigger_on, :_index_names, :entity_type, :_index_type, :_field_types
8
+ attr_reader :_trigger_on, :_index_names, :entity_type
9
9
 
10
- # @param [:rel, :node] entity_type the type of index
11
10
  def initialize(entity_type)
12
11
  @entity_type = entity_type
13
- @_index_type = {}
14
- @_field_types = {}
12
+ @index_type = {}
13
+ @numeric_types = []
15
14
  @_trigger_on = {}
16
- end
17
-
18
- def to_s
19
- "IndexConfig [#@entity_type, _index_type: #{@_index_type.inspect}, _field_types: #{@_field_types.inspect}, _trigger_on: #{@_trigger_on.inspect}]"
20
- end
21
-
22
- def inherit_from(clazz)
23
- c = clazz._indexer.config
24
- raise "Can't inherit from different index type #{@entity_type} != #{c.entity_type}" if @entity_type != c.entity_type
25
- @_index_type.merge!(c._index_type)
26
- @_field_types.merge!(c._field_types)
15
+ @decl_type = {}
27
16
  end
28
17
 
29
18
  # Specifies which property and values the index should be triggered on.
@@ -33,8 +22,11 @@ module Neo4j
33
22
  merge_and_to_string(@_trigger_on, hash)
34
23
  end
35
24
 
36
- def field_type(key)
37
- @_field_types[key.to_s]
25
+ # Specifies the types of the properties being indexed so that the proper sort order can be applied.
26
+ # Used in the Index DSL.
27
+ # @see Neo4j::Core::Index::ClassMethods#node_indexer
28
+ def decl_type(prop_and_type_hash)
29
+ merge_and_to_string(@decl_type, prop_and_type_hash)
38
30
  end
39
31
 
40
32
  # Specifies an index with configuration
@@ -45,15 +37,15 @@ module Neo4j
45
37
  conf = args.last.kind_of?(Hash) ? args.pop : {}
46
38
 
47
39
  args.uniq.each do |field|
48
- @_index_type[field.to_s] = conf[:type] || :exact
49
- @_field_types[field.to_s] = conf[:field_type] || String
40
+ @index_type[field.to_s] = conf[:type] || :exact
41
+ @numeric_types << field.to_s if conf[:numeric] == true
50
42
  end
51
43
  end
52
44
 
53
- # @return [Class,nil] the specified type of the property or nil
45
+ # @return [Class] the specified type of the property or String
54
46
  # @see #decl_type
55
47
  def decl_type_on(prop)
56
- @_field_types[prop]
48
+ @decl_type[prop] || String
57
49
  end
58
50
 
59
51
  # @return [true, false] if the props can/should trigger an index operation
@@ -79,30 +71,31 @@ module Neo4j
79
71
  @_index_names = hash
80
72
  end
81
73
 
74
+
82
75
  def rm_index_config
83
- @_index_type = {}
84
- @_field_types = {}
76
+ @index_type = {}
77
+ @numeric_types = []
85
78
  end
86
79
 
87
80
  def index_type(field)
88
- @_index_type[field.to_s]
81
+ @index_type[field.to_s]
89
82
  end
90
83
 
91
84
  def has_index_type?(type)
92
- @_index_type.values.include?(type)
85
+ @index_type.values.include?(type)
93
86
  end
94
87
 
95
88
  def fields
96
- @_index_type.keys
89
+ @index_type.keys
97
90
  end
98
91
 
99
92
  def index?(field)
100
- @_index_type.include?(field.to_s)
93
+ @index_type.include?(field.to_s)
101
94
  end
102
95
 
103
96
  def numeric?(field)
104
- raise "No index on #{field.inspect}, has fields: #{@field_types.inspect}" unless @_field_types[field]
105
- @_field_types[field] != String
97
+ return true if @numeric_types.include?(field)
98
+ # TODO callback to numeric dsl for Neo4j::NodeMixin decl_props check
106
99
  end
107
100
 
108
101
  private
@@ -110,7 +103,7 @@ module Neo4j
110
103
  def merge_and_to_string(existing_hash, new_hash)
111
104
  new_hash.each_pair do |k, v|
112
105
  existing_hash[k.to_s] ||= Set.new
113
- existing_hash[k.to_s].merge(v.is_a?(Array) ? v : [v])
106
+ existing_hash[k.to_s].merge(v.is_a?(Array)? v : [v])
114
107
  end
115
108
  end
116
109
  end
@@ -17,21 +17,55 @@ module Neo4j
17
17
 
18
18
 
19
19
  def to_s
20
- "Indexer @#{object_id} index on: [#{@config.fields.map { |f| @config.numeric?(f) ? "#{f} (numeric)" : f }.join(', ')}]"
20
+ "Indexer @#{object_id} index on: [#{@config.fields.map{|f| @config.numeric?(f)? "#{f} (numeric)" : f}.join(', ')}]"
21
21
  end
22
22
 
23
23
  # Add an index on a field so that it will be automatically updated by neo4j transactional events.
24
- # Notice that if you want to numerical range queries then you should specify a field_type of either Fixnum or Float.
25
- # The index type will by default be <tt>:exact</tt>.
26
- # Index on property arrays are supported.
27
24
  #
28
- # @example
29
- # MyIndex.index(:age, :field_type => Fixnum) # default :exact
30
- # MyIndex.index(:wheels, :field_type => Fixnum)
31
- # MyIndex.index(:description, :type => :fulltext)
25
+ # The index method takes an optional configuration hash which allows you to:
26
+ #
27
+ # @example Add an index on an a property
28
+ #
29
+ # class Person
30
+ # include Neo4j::NodeMixin
31
+ # index :name
32
+ # end
33
+ #
34
+ # When the property name is changed/deleted or the node created it will keep the lucene index in sync.
35
+ # You can then perform a lucene query like this: Person.find('name: andreas')
36
+ #
37
+ # @example Add index on other nodes.
38
+ #
39
+ # class Person
40
+ # include Neo4j::NodeMixin
41
+ # has_n(:friends).to(Contact)
42
+ # has_n(:known_by).from(:friends)
43
+ # index :user_id, :via => :known_by
44
+ # end
45
+ #
46
+ # Notice that you *must* specify an incoming relationship with the via key, as shown above.
47
+ # In the example above an index <tt>user_id</tt> will be added to all Person nodes which has a <tt>friends</tt> relationship
48
+ # that person with that user_id. This allows you to do lucene queries on your friends properties.
49
+ #
50
+ # @example Set the type value to index
51
+ #
52
+ # class Person
53
+ # include Neo4j::NodeMixin
54
+ # property :height, :weight, :type => Float
55
+ # index :height, :weight
56
+ # end
57
+ #
58
+ # By default all values will be indexed as Strings.
59
+ # If you want for example to do a numerical range query you must tell Neo4j.rb to index it as a numeric value.
60
+ # You do that with the key <tt>type</tt> on the property.
61
+ #
62
+ # Supported values for <tt>:type</tt> is <tt>String</tt>, <tt>Float</tt>, <tt>Date</tt>, <tt>DateTime</tt> and <tt>Fixnum</tt>
63
+ #
64
+ # === For more information
32
65
  #
33
66
  # @see Neo4j::Core::Index::LuceneQuery
34
67
  # @see #find
68
+ #
35
69
  def index(*args)
36
70
  @config.index(args)
37
71
  end
@@ -62,18 +96,11 @@ module Neo4j
62
96
  # @see #index
63
97
  def add_index(entity, field, value)
64
98
  return false unless index?(field)
65
- if (java_array?(value))
66
- conv_value = value.map{|x| indexed_value_for(field, x)}.to_java(Java::OrgNeo4jIndexLucene::ValueContext)
67
- else
68
- conv_value = indexed_value_for(field, value)
69
- end
99
+ conv_value = indexed_value_for(field, value)
70
100
  index = index_for_field(field.to_s)
71
101
  index.add(entity, field, conv_value)
72
102
  end
73
103
 
74
- def java_array?(value)
75
- value.respond_to?(:java_class) && value.java_class.to_s[0..0] == '['
76
- end
77
104
 
78
105
  # Removes an index on the given entity
79
106
  # This is normally not needed since you can instead declare an index which will automatically keep
@@ -81,7 +108,6 @@ module Neo4j
81
108
  # @see #index
82
109
  def rm_index(entity, field, value)
83
110
  return false unless index?(field)
84
- #return value.each {|x| rm_index(entity, field, x)} if value.respond_to?(:each)
85
111
  index_for_field(field).remove(entity, field, value)
86
112
  end
87
113
 
@@ -94,44 +120,23 @@ module Neo4j
94
120
  # (by Rack).
95
121
  #
96
122
  # @example with a block
97
- # Person.find('name: kalle') {|query| puts "First item #{query.first}"}
98
123
  #
99
- # @example using an exact lucene index
100
- # query = Person.find('name: kalle')
101
- # puts "First item #{query.first}"
102
- # query.close
124
+ # Person.find('name: kalle') {|query| puts "#{[*query].join(', )"}
103
125
  #
104
- # @example using an fulltext lucene index
105
- # query = Person.find('name: kalle', :type => :fulltext)
126
+ # @example
127
+ #
128
+ # query = Person.find('name: kalle')
106
129
  # puts "First item #{query.first}"
107
130
  # query.close
108
131
  #
109
- # @example Sorting, descending by one property
110
- # Person.find({:name => 'kalle'}, :sort => {:name => :desc})
111
- #
112
- # @example Sorting using the builder pattern
113
- # Person.find(:name => 'kalle').asc(:name)
114
- #
115
- # @example Searching by a set of values, OR search
116
- # Person.find(:name => ['kalle', 'sune', 'jimmy'])
117
- #
118
- # @example Compound queries and Range queries
119
- # Person.find('name: pelle').and(:age).between(2, 5)
120
- # Person.find(:name => 'kalle', :age => (2..5))
121
- # Person.find("name: 'asd'").and(:wheels => 8)
122
- #
123
- # @example Using the lucene java object
124
- # # using the Neo4j query method directly
125
- # # see, http://api.neo4j.org/1.6.1/org/neo4j/graphdb/index/ReadableIndex.html#query(java.lang.Object)
126
- # MyIndex.find('description: "hej"', :type => :fulltext, :wrapped => false).get_single
127
- #
128
- # @param [String, Hash] query the lucene query
129
- # @param [Hash] params lucene configuration parameters
130
- # @return [Neo4j::Core::Index::LuceneQuery] a query object which uses the builder pattern for creating compound and sort queries.
131
- # @note You must specify the index type <tt>:fulltext<tt>) if the property is index using that index (default is <tt>:exact</tt>)
132
+ # @return [Neo4j::Core::Index::LuceneQuery] a query object
132
133
  def find(query, params = {})
133
134
  index = index_for_type(params[:type] || :exact)
134
- query.delete(:sort) if query.is_a?(Hash) && query.include?(:sort)
135
+ if query.is_a?(Hash) && (query.include?(:conditions) || query.include?(:sort))
136
+ params.merge! query.reject { |k, _| k == :conditions }
137
+ query.delete(:sort)
138
+ query = query.delete(:conditions) if query.include?(:conditions)
139
+ end
135
140
  query = (params[:wrapped].nil? || params[:wrapped]) ? LuceneQuery.new(index, @config, query, params) : index.query(query)
136
141
 
137
142
  if block_given?
@@ -146,23 +151,6 @@ module Neo4j
146
151
  end
147
152
  end
148
153
 
149
- # Add the entity to this index for the given key/value pair if this particular key/value pair doesn't already exist.
150
- # This ensures that only one entity will be associated with the key/value pair even if multiple transactions are trying to add it at the same time.
151
- # One of those transactions will win and add it while the others will block, waiting for the winning transaction to finish.
152
- # If the winning transaction was successful these other transactions will return the associated entity instead of adding it.
153
- # If it wasn't successful the waiting transactions will begin a new race to add it.
154
- #
155
- # @param [Neo4j::Node, Neo4j::Relationship] entity the entity (i.e Node or Relationship) to associate the key/value pair with.
156
- # @param [String, Symbol] key the key in the key/value pair to associate with the entity.
157
- # @param [String, Fixnum, Float] value the value in the key/value pair to associate with the entity.
158
- # @param [Symbol] index_type the type of lucene index
159
- # @return [nil, Neo4j:Node, Neo4j::Relationship] the previously indexed entity, or nil if no entity was indexed before (and the specified entity was added to the index).
160
- # @see Neo4j::Core::Index::UniqueFactory as an alternative which probably simplify creating unique entities
161
- def put_if_absent(entity, key, value, index_type = :exact)
162
- index = index_for_type(index_type)
163
- index.put_if_absent(entity, key.to_s, value)
164
- end
165
-
166
154
  # Delete all index configuration. No more automatic indexing will be performed
167
155
  def rm_index_config
168
156
  @config.rm_index_config
@@ -7,7 +7,7 @@ module Neo4j
7
7
  end
8
8
 
9
9
  def delete_all_indexes
10
- @indexers.each { |i| i.rm_index_type }
10
+ @indexers.values.each { |i| i.rm_index_type }
11
11
  end
12
12
 
13
13
  def register(indexer)
@@ -16,7 +16,7 @@ module Neo4j
16
16
  end
17
17
 
18
18
  def indexers_for(props)
19
- Enumerator.new(self, :each_indexer, props)
19
+ Enumerable::Enumerator.new(self, :each_indexer, props)
20
20
  end
21
21
 
22
22
  def each_indexer(props)
@@ -39,7 +39,11 @@ module Neo4j
39
39
  @query = query
40
40
  @index_config = index_config
41
41
  @params = params
42
- @order = params[:sort] if params.include?(:sort)
42
+
43
+ if params.include?(:sort)
44
+ @order = {}
45
+ params[:sort].each_pair { |k, v| @order[k] = (v == :desc) }
46
+ end
43
47
  end
44
48
 
45
49
  # Implements the Ruby +Enumerable+ interface
@@ -81,26 +85,30 @@ module Neo4j
81
85
  # Performs a range query
82
86
  # Notice that if you don't specify a type when declaring a property a String range query will be performed.
83
87
  #
84
- def between(lower, upper, lower_inclusive=false, upper_inclusive=false)
88
+ def between(lower, upper, lower_incusive=false, upper_inclusive=false)
85
89
  raise "Expected a symbol. Syntax for range queries example: index(:weight).between(a,b)" unless Symbol === @query
86
- @query = range_query(@query, lower, upper, lower_inclusive, upper_inclusive)
90
+ # raise "Can't only do range queries on Neo4j::NodeMixin, Neo4j::Model, Neo4j::RelationshipMixin" unless @decl_props
91
+ # check that we perform a range query on the same values as we have declared with the property :key, :type => ...
92
+ type = @index_config.decl_type_on(@query)
93
+ raise "find(#{@query}).between(#{lower}, #{upper}): #{lower} not a #{type}" if type && !type === lower.class
94
+ raise "find(#{@query}).between(#{lower}, #{upper}): #{upper} not a #{type}" if type && !type === upper.class
95
+
96
+ # Make it possible to convert those values
97
+ @query = range_query(@query, lower, upper, lower_incusive, upper_inclusive)
87
98
  self
88
99
  end
89
100
 
90
- def range_query(field, lower, upper, lower_inclusive, upper_inclusive)
91
- type = @index_config.field_type(field)
92
- raise "no index on field #{field}" unless type
93
- # check that we perform a range query on the same values as we have declared with the property :key, :type => ...
94
- raise "find(#{field}).between(#{lower}, #{upper}): #{lower} not a #{type}" unless type == lower.class
95
- raise "find(#{field}).between(#{lower}, #{upper}): #{upper} not a #{type}" unless type == upper.class
101
+ def range_query(field, lower, upper, lower_incusive, upper_inclusive)
102
+ lower = TypeConverters.convert(lower)
103
+ upper = TypeConverters.convert(upper)
96
104
 
97
105
  case lower
98
106
  when Fixnum
99
- Java::OrgApacheLuceneSearch::NumericRangeQuery.new_long_range(field.to_s, lower, upper, lower_inclusive, upper_inclusive)
107
+ Java::OrgApacheLuceneSearch::NumericRangeQuery.new_long_range(field.to_s, lower, upper, lower_incusive, upper_inclusive)
100
108
  when Float
101
- Java::OrgApacheLuceneSearch::NumericRangeQuery.new_double_range(field.to_s, lower, upper, lower_inclusive, upper_inclusive)
109
+ Java::OrgApacheLuceneSearch::NumericRangeQuery.new_double_range(field.to_s, lower, upper, lower_incusive, upper_inclusive)
102
110
  else
103
- Java::OrgApacheLuceneSearch::TermRangeQuery.new(field.to_s, lower, upper, lower_inclusive, upper_inclusive)
111
+ Java::OrgApacheLuceneSearch::TermRangeQuery.new(field.to_s, lower, upper, lower_incusive, upper_inclusive)
104
112
  end
105
113
  end
106
114
 
@@ -148,28 +156,19 @@ module Neo4j
148
156
  # Sort descending the given fields.
149
157
  # @param [Symbol] fields it should sort
150
158
  def desc(*fields)
151
- @order ||= []
152
- @order += fields.map { |f| [f, :desc] }
159
+ @order = fields.inject(@order || {}) { |memo, field| memo[field] = true; memo }
153
160
  self
154
161
  end
155
162
 
156
163
  # Sort ascending the given fields.
157
164
  # @param [Symbol] fields it should sort
158
165
  def asc(*fields)
159
- @order ||= []
160
- @order += fields.map { |f| [f, :asc] }
166
+ @order = fields.inject(@order || {}) { |memo, field| memo[field] = false; memo }
161
167
  self
162
168
  end
163
169
 
164
170
  protected
165
171
 
166
- def parse_query(query)
167
- version = Java::OrgApacheLuceneUtil::Version::LUCENE_30
168
- analyzer = Java::OrgApacheLuceneAnalysisStandard::StandardAnalyzer.new(version)
169
- parser = Java::org.apache.lucene.queryParser.QueryParser.new(version, 'name', analyzer)
170
- parser.parse(query)
171
- end
172
-
173
172
  def build_and_query(query)
174
173
  build_composite_query(@left_and_query.build_query, query, Java::OrgApacheLuceneSearch::BooleanClause::Occur::MUST)
175
174
  end
@@ -180,9 +179,6 @@ module Neo4j
180
179
 
181
180
  def build_not_query(query)
182
181
  right_query = @right_not_query.build_query
183
- query = parse_query(query) if query.is_a?(String)
184
- right_query = parse_query(right_query) if right_query.is_a?(String)
185
-
186
182
  composite_query = Java::OrgApacheLuceneSearch::BooleanQuery.new
187
183
  composite_query.add(query, Java::OrgApacheLuceneSearch::BooleanClause::Occur::MUST_NOT)
188
184
  composite_query.add(right_query, Java::OrgApacheLuceneSearch::BooleanClause::Occur::MUST)
@@ -190,27 +186,31 @@ module Neo4j
190
186
  end
191
187
 
192
188
  def build_composite_query(left_query, right_query, operator) #:nodoc:
193
- left_query = parse_query(left_query) if left_query.is_a?(String)
194
- right_query = parse_query(right_query) if right_query.is_a?(String)
195
189
  composite_query = Java::OrgApacheLuceneSearch::BooleanQuery.new
190
+ version = Java::OrgApacheLuceneUtil::Version::LUCENE_35
191
+ analyzer = org.apache.lucene.analysis.standard::StandardAnalyzer.new(version)
192
+ parser = Java::org.apache.lucene.queryParser.QueryParser.new(version,'name', analyzer )
193
+
194
+ left_query = parser.parse(left_query) if left_query.is_a?(String)
195
+ right_query = parser.parse(right_query) if right_query.is_a?(String)
196
+
196
197
  composite_query.add(left_query, operator)
197
198
  composite_query.add(right_query, operator)
198
199
  composite_query
199
200
  end
200
201
 
201
202
  def build_sort_query(query) #:nodoc:
202
- java_sort_fields = @order.inject([]) do |memo, val|
203
- field = val[0]
204
- field_type = @index_config.field_type(field)
203
+ java_sort_fields = @order.keys.inject([]) do |memo, field|
204
+ decl_type = @index_config.decl_type_on(field)
205
205
  type = case
206
- when Float == field_type
206
+ when Float == decl_type
207
207
  Java::OrgApacheLuceneSearch::SortField::DOUBLE
208
- when Fixnum == field_type
208
+ when Fixnum == decl_type || DateTime == decl_type || Date == decl_type || Time == decl_type
209
209
  Java::OrgApacheLuceneSearch::SortField::LONG
210
210
  else
211
211
  Java::OrgApacheLuceneSearch::SortField::STRING
212
212
  end
213
- memo << Java::OrgApacheLuceneSearch::SortField.new(field.to_s, type, val[1] == :desc)
213
+ memo << Java::OrgApacheLuceneSearch::SortField.new(field.to_s, type, @order[field])
214
214
  end
215
215
  sort = Java::OrgApacheLuceneSearch::Sort.new(*java_sort_fields)
216
216
  Java::OrgNeo4jIndexLucene::QueryContext.new(query).sort(sort)
@@ -220,29 +220,18 @@ module Neo4j
220
220
  and_query = Java::OrgApacheLuceneSearch::BooleanQuery.new
221
221
 
222
222
  query.each_pair do |key, value|
223
- type = @index_config.field_type(key)
224
- if type != String
223
+ type = @index_config && @index_config[key.to_sym] && @index_config[key.to_sym][:type]
224
+ if !type.nil? && type != String
225
225
  if Range === value
226
- and_query.add(range_query(key, value.first, value.last, true, !value.exclude_end?), Java::OrgApacheLuceneSearch::BooleanClause::Occur::MUST)
227
- elsif Array === value
228
- value.each do |v|
229
- and_query.add(range_query(key, v, v, true, true), Java::OrgApacheLuceneSearch::BooleanClause::Occur::SHOULD)
230
- end
226
+ and_query.add(range_query(key, value.first, value.last, true, !value.exclude_end?), Java::OrgApacheLuceneIndex::BooleanClause::Occur::MUST)
231
227
  else
232
- and_query.add(range_query(key, value, value, true, true), Java::OrgApacheLuceneSearch::BooleanClause::Occur::MUST)
228
+ and_query.add(range_query(key, value, value, true, true), Java::OrgApacheLuceneIndex::BooleanClause::Occur::MUST)
233
229
  end
234
230
  else
235
- if Array === value
236
- value.each do |v|
237
- term = Java::OrgApacheLuceneIndex::Term.new(key.to_s, v.to_s)
238
- term_query = Java::OrgApacheLuceneSearch::TermQuery.new(term)
239
- and_query.add(term_query, Java::OrgApacheLuceneSearch::BooleanClause::Occur::SHOULD)
240
- end
241
- else
242
- term = Java::OrgApacheLuceneIndex::Term.new(key.to_s, value.to_s)
243
- term_query = Java::OrgApacheLuceneSearch::TermQuery.new(term)
244
- and_query.add(term_query, Java::OrgApacheLuceneSearch::BooleanClause::Occur::MUST)
245
- end
231
+ conv_value = type ? TypeConverters.convert(value) : value.to_s
232
+ term = Java::OrgApacheLuceneIndex::Term.new(key.to_s, conv_value)
233
+ term_query = Java::OrgApacheLuceneIndex::TermQuery.new(term)
234
+ and_query.add(term_query, Java::OrgApacheLuceneIndex::BooleanClause::Occur::MUST)
246
235
  end
247
236
  end
248
237
  and_query