neo4j-core 0.0.4-java → 0.0.5-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +2 -2
- data/lib/neo4j-core.rb +1 -0
- data/lib/neo4j-core/index/indexer.rb +36 -52
- data/lib/neo4j-core/property/java.rb +59 -0
- data/lib/neo4j-core/relationship/relationship.rb +4 -0
- data/lib/neo4j-core/version.rb +1 -1
- data/lib/neo4j/node.rb +1 -0
- data/lib/neo4j/relationship.rb +2 -0
- data/neo4j-core.gemspec +1 -1
- metadata +4 -3
data/Gemfile
CHANGED
@@ -2,8 +2,8 @@ source :gemcutter
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'neo4j-advanced', "1.7.
|
6
|
-
gem 'neo4j-enterprise', "1.7.
|
5
|
+
gem 'neo4j-advanced', "1.7.M02", :require => false
|
6
|
+
gem 'neo4j-enterprise', "1.7.M02", :require => false
|
7
7
|
|
8
8
|
group 'development' do
|
9
9
|
gem 'guard'
|
data/lib/neo4j-core.rb
CHANGED
@@ -17,55 +17,21 @@ 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.
|
24
27
|
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
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
|
28
|
+
# @example
|
29
|
+
# MyIndex.index(:age, :field_type => Fixnum) # default :exact
|
30
|
+
# MyIndex.index(:wheels, :field_type => Fixnum)
|
31
|
+
# MyIndex.index(:description, :type => :fulltext)
|
65
32
|
#
|
66
33
|
# @see Neo4j::Core::Index::LuceneQuery
|
67
34
|
# @see #find
|
68
|
-
#
|
69
35
|
def index(*args)
|
70
36
|
@config.index(args)
|
71
37
|
end
|
@@ -96,11 +62,18 @@ module Neo4j
|
|
96
62
|
# @see #index
|
97
63
|
def add_index(entity, field, value)
|
98
64
|
return false unless index?(field)
|
99
|
-
|
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
|
100
70
|
index = index_for_field(field.to_s)
|
101
71
|
index.add(entity, field, conv_value)
|
102
72
|
end
|
103
73
|
|
74
|
+
def java_array?(value)
|
75
|
+
value.respond_to?(:java_class) && value.java_class.to_s[0..0] == '['
|
76
|
+
end
|
104
77
|
|
105
78
|
# Removes an index on the given entity
|
106
79
|
# This is normally not needed since you can instead declare an index which will automatically keep
|
@@ -108,6 +81,7 @@ module Neo4j
|
|
108
81
|
# @see #index
|
109
82
|
def rm_index(entity, field, value)
|
110
83
|
return false unless index?(field)
|
84
|
+
#return value.each {|x| rm_index(entity, field, x)} if value.respond_to?(:each)
|
111
85
|
index_for_field(field).remove(entity, field, value)
|
112
86
|
end
|
113
87
|
|
@@ -120,23 +94,33 @@ module Neo4j
|
|
120
94
|
# (by Rack).
|
121
95
|
#
|
122
96
|
# @example with a block
|
123
|
-
#
|
124
97
|
# Person.find('name: kalle') {|query| puts "#{[*query].join(', )"}
|
125
98
|
#
|
126
|
-
# @example
|
127
|
-
#
|
99
|
+
# @example using an exact lucene index
|
128
100
|
# query = Person.find('name: kalle')
|
129
101
|
# puts "First item #{query.first}"
|
130
102
|
# query.close
|
131
103
|
#
|
132
|
-
# @
|
104
|
+
# @example using an fulltext lucene index
|
105
|
+
# query = Person.find('name: kalle', :type => :fulltext)
|
106
|
+
# puts "First item #{query.first}"
|
107
|
+
# query.close
|
108
|
+
#
|
109
|
+
# @example Sorting, descending by one property
|
110
|
+
# Person.find({:name => 'kalle'}, :sort => {:name => :desc})
|
111
|
+
#
|
112
|
+
# @example Using the lucene java object
|
113
|
+
# # using the Neo4j query method directly
|
114
|
+
# # see, http://api.neo4j.org/1.6.1/org/neo4j/graphdb/index/ReadableIndex.html#query(java.lang.Object)
|
115
|
+
# MyIndex.find('description: "hej"', :type => :fulltext, :wrapped => false).get_single
|
116
|
+
#
|
117
|
+
# @param [String, Hash] query the lucene query
|
118
|
+
# @param [Hash] params lucene configuration parameters
|
119
|
+
# @return [Neo4j::Core::Index::LuceneQuery] a query object which uses the builder pattern for creating compound and sort queries.
|
120
|
+
# @note You must specify the index type <tt>:fulltext<tt>) if the property is index using that index (default is <tt>:exact</tt>)
|
133
121
|
def find(query, params = {})
|
134
122
|
index = index_for_type(params[:type] || :exact)
|
135
|
-
|
136
|
-
params.merge! query.reject { |k, _| k == :conditions }
|
137
|
-
query.delete(:sort)
|
138
|
-
query = query.delete(:conditions) if query.include?(:conditions)
|
139
|
-
end
|
123
|
+
query.delete(:sort) if query.is_a?(Hash) && query.include?(:sort)
|
140
124
|
query = (params[:wrapped].nil? || params[:wrapped]) ? LuceneQuery.new(index, @config, query, params) : index.query(query)
|
141
125
|
|
142
126
|
if block_given?
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Neo4j
|
2
|
+
module Core
|
3
|
+
module Property
|
4
|
+
# This module is only used for documentation purpose
|
5
|
+
# It simplify declares the java methods which are available Java org.neo4j.graphdb.PropertyContainer
|
6
|
+
# @see http://api.neo4j.org/1.6.1/org/neo4j/graphdb/PropertyContainer.html
|
7
|
+
module Java
|
8
|
+
|
9
|
+
|
10
|
+
# Get the GraphDatabaseService that this Node or Relationship belongs to.
|
11
|
+
# @return [Java::Neo4jGraphdbGraphDatabaseService]
|
12
|
+
def graph_database
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns the property value associated with the given key, or a default value.
|
16
|
+
# The value is of one of the valid property types, i.e. a Java primitive, a String or an array of any of the valid types.
|
17
|
+
# If there's no property associated with key an unchecked exception is raised.
|
18
|
+
# The idiomatic way to avoid an exception for an unknown key and instead get null back is to use a default value: Object valueOrNull = nodeOrRel.getProperty( key, null )
|
19
|
+
# @param [String] key the property key
|
20
|
+
# @param [String] default_value the default value that will be returned if no property value was associated with the given key
|
21
|
+
# @return [String,Fixnum,Boolean,Float,Array] ]the property value associated with the given key.
|
22
|
+
# @raise an exception if not given a default value and there is no property for the given key
|
23
|
+
# @see Neo4j::Core:Property#[]
|
24
|
+
def get_property(key, default_value = nil)
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return all existing property keys, or an empty iterable if this property container has no properties.
|
28
|
+
def property_keys
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
# Removes the property associated with the given key and returns the old value.
|
33
|
+
# @param [String] key the name of the property
|
34
|
+
# @return [String,Fixnum,Boolean,Float,Array, nil] The old value or <tt>nil</tt> if there's no property associated with the key.
|
35
|
+
def remove_property(key)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Sets the property value for the given key to value.
|
39
|
+
# The property value must be one of the valid property types, i.e:
|
40
|
+
# * boolean or boolean[]
|
41
|
+
# * byte or byte[]
|
42
|
+
# * short or short[]
|
43
|
+
# * int or int[]
|
44
|
+
# * long or long[]
|
45
|
+
# * float or float[]
|
46
|
+
# * double or double[]
|
47
|
+
# * char or char[]
|
48
|
+
# * java.lang.String or String[]
|
49
|
+
# Notice that JRuby does map Ruby primitive object (e.g. Fixnum) to java primitives automatically.
|
50
|
+
# Also, nil is not an accepted property value.
|
51
|
+
# @param [String] key the property key
|
52
|
+
# @param [String,Fixnum,Boolean,Float,Array] value
|
53
|
+
# @see Neo4j::Core::Property#[]=
|
54
|
+
def set_property(key, value)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -3,16 +3,19 @@ module Neo4j
|
|
3
3
|
module Relationship
|
4
4
|
|
5
5
|
# Same as Java::OrgNeo4jGraphdb::Relationship#getEndNode
|
6
|
+
# @see http://api.neo4j.org/1.6.1/org/neo4j/graphdb/Relationship.html#getEndNode()
|
6
7
|
def _end_node
|
7
8
|
get_end_node
|
8
9
|
end
|
9
10
|
|
10
11
|
# Same as Java::OrgNeo4jGraphdb::Relationship#getStartNode
|
12
|
+
# @see http://api.neo4j.org/1.6.1/org/neo4j/graphdb/Relationship.html#getStartNode()
|
11
13
|
def _start_node
|
12
14
|
get_start_node
|
13
15
|
end
|
14
16
|
|
15
17
|
# Same as Java::OrgNeo4jGraphdb::Relationship#getOtherNode
|
18
|
+
# @see http://api.neo4j.org/1.6.1/org/neo4j/graphdb/Relationship.html#getOtherNode()
|
16
19
|
def _other_node(node)
|
17
20
|
get_other_node(node)
|
18
21
|
end
|
@@ -49,6 +52,7 @@ module Neo4j
|
|
49
52
|
#
|
50
53
|
# @param [Neo4j::Node] node the node that we don't want to return
|
51
54
|
# @return [Neo4j::Node] the other node wrapper
|
55
|
+
# @see #_other_node
|
52
56
|
def other_node(node)
|
53
57
|
_other_node(node._java_node).wrapper
|
54
58
|
end
|
data/lib/neo4j-core/version.rb
CHANGED
data/lib/neo4j/node.rb
CHANGED
data/lib/neo4j/relationship.rb
CHANGED
@@ -39,6 +39,8 @@ module Neo4j
|
|
39
39
|
include Neo4j::Core::Equal
|
40
40
|
include Neo4j::Core::Relationship
|
41
41
|
include Neo4j::Core::Wrapper
|
42
|
+
include Neo4j::Core::Property::Java # for documentation purpose only
|
43
|
+
|
42
44
|
|
43
45
|
# (see Neo4j::Core::Relationship::ClassMethods#new)
|
44
46
|
def initialize(rel_type, start_node, end_node, props={})
|
data/neo4j-core.gemspec
CHANGED
@@ -27,5 +27,5 @@ It comes included with the Apache Lucene document database.
|
|
27
27
|
s.extra_rdoc_files = %w( README.rdoc )
|
28
28
|
s.rdoc_options = ["--quiet", "--title", "Neo4j::Core", "--line-numbers", "--main", "README.rdoc", "--inline-source"]
|
29
29
|
|
30
|
-
s.add_dependency("neo4j-community", "1.7.
|
30
|
+
s.add_dependency("neo4j-community", "1.7.M02")
|
31
31
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: neo4j-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.5
|
6
6
|
platform: java
|
7
7
|
authors:
|
8
8
|
- Andreas Ronge
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-04-01 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: neo4j-community
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - "="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 1.7.
|
23
|
+
version: 1.7.M02
|
24
24
|
type: :runtime
|
25
25
|
version_requirements: *id001
|
26
26
|
description: |
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- lib/neo4j-core/to_java.rb
|
54
54
|
- lib/neo4j-core/node/node.rb
|
55
55
|
- lib/neo4j-core/node/class_methods.rb
|
56
|
+
- lib/neo4j-core/property/java.rb
|
56
57
|
- lib/neo4j-core/property/property.rb
|
57
58
|
- lib/neo4j-core/equal/equal.rb
|
58
59
|
- lib/neo4j-core/traversal/rel_expander.rb
|