neo4j 1.0.0.beta.2 → 1.0.0.beta.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,18 +8,21 @@ module Neo4j
8
8
 
9
9
 
10
10
  def start
11
- @running = true
12
11
  @graph = org.neo4j.kernel.EmbeddedGraphDatabase.new(Config[:storage_path])
13
12
  @lucene = org.neo4j.index.impl.lucene.LuceneIndexProvider.new(@graph)
14
13
  @graph.register_transaction_event_handler(@event_handler)
14
+ @running = true
15
15
  @event_handler.neo4j_started(self)
16
+ at_exit { shutdown }
16
17
  end
17
18
 
18
19
  def shutdown
19
- @running = false
20
- @graph.unregister_transaction_event_handler(@event_handler)
21
- @event_handler.neo4j_shutdown(self)
20
+ if @running
21
+ @graph.unregister_transaction_event_handler(@event_handler)
22
+ @event_handler.neo4j_shutdown(self)
23
+ end
22
24
  @graph.shutdown
25
+ @running = false
23
26
  end
24
27
 
25
28
  def running?
data/lib/neo4j/index.rb CHANGED
@@ -56,9 +56,29 @@ module Neo4j
56
56
  end
57
57
 
58
58
  def hits
59
- @hits ||= @index.query(@query)
59
+ @hits ||= perform_query
60
60
  end
61
61
 
62
+ def desc(*fields)
63
+ @order = fields.inject(@order || {}){|memo, field| memo[field] = true; memo}
64
+ self
65
+ end
66
+
67
+ def asc(*fields)
68
+ @order = fields.inject(@order || {}){|memo, field| memo[field] = false; memo}
69
+ self
70
+ end
71
+
72
+ def perform_query
73
+ if @order
74
+ java_sort_fields = @order.keys.inject([]) do |memo, field|
75
+ memo << org.apache.lucene.search.SortField.new(field.to_s, org.apache.lucene.search.SortField::STRING, @order[field])
76
+ end
77
+ sort = org.apache.lucene.search.Sort.new(*java_sort_fields)
78
+ @query = org.neo4j.index.impl.lucene.QueryContext.new(@query).sort(sort)
79
+ end
80
+ @index.query(@query)
81
+ end
62
82
  end
63
83
 
64
84
  class Indexer
data/lib/neo4j/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Neo4j
2
- VERSION = "1.0.0.beta.2"
2
+ VERSION = "1.0.0.beta.3"
3
3
  end
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 0
8
8
  - 0
9
9
  - beta
10
- - 2
11
- version: 1.0.0.beta.2
10
+ - 3
11
+ version: 1.0.0.beta.3
12
12
  platform: ruby
13
13
  authors:
14
14
  - Andreas Ronge
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-09-23 00:00:00 +02:00
19
+ date: 2010-09-25 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency