redcar 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +6 -0
- data/Rakefile +1 -1
- data/lib/redcar.rb +2 -2
- data/lib/redcar/installer.rb +3 -2
- metadata +4 -62
- data/plugins/project_search/vendor/lucene/CHANGELOG +0 -147
- data/plugins/project_search/vendor/lucene/CONTRIBUTORS +0 -17
- data/plugins/project_search/vendor/lucene/Gemfile +0 -9
- data/plugins/project_search/vendor/lucene/Gemfile.lock +0 -33
- data/plugins/project_search/vendor/lucene/LICENSE +0 -19
- data/plugins/project_search/vendor/lucene/README.rdoc +0 -283
- data/plugins/project_search/vendor/lucene/Rakefile +0 -35
- data/plugins/project_search/vendor/lucene/examples/active_model/serializers.rb +0 -25
- data/plugins/project_search/vendor/lucene/examples/active_model/validation.rb +0 -26
- data/plugins/project_search/vendor/lucene/examples/admin/Rakefile +0 -4
- data/plugins/project_search/vendor/lucene/examples/admin/admin.rb +0 -29
- data/plugins/project_search/vendor/lucene/examples/admin/public/jquery.js +0 -4376
- data/plugins/project_search/vendor/lucene/examples/admin/public/neo4j.css +0 -153
- data/plugins/project_search/vendor/lucene/examples/admin/public/neo_admin.js +0 -18
- data/plugins/project_search/vendor/lucene/examples/admin/spec/admin_spec.rb +0 -26
- data/plugins/project_search/vendor/lucene/examples/admin/views/index.erb +0 -21
- data/plugins/project_search/vendor/lucene/examples/filetree/README.rdoc +0 -9
- data/plugins/project_search/vendor/lucene/examples/filetree/app.rb +0 -7
- data/plugins/project_search/vendor/lucene/examples/filetree/batch.props +0 -5
- data/plugins/project_search/vendor/lucene/examples/filetree/features/step_definitions/add_steps.rb +0 -121
- data/plugins/project_search/vendor/lucene/examples/filetree/features/support/env.rb +0 -30
- data/plugins/project_search/vendor/lucene/examples/filetree/features/support/rspec_helper.rb +0 -50
- data/plugins/project_search/vendor/lucene/examples/filetree/features/treesizes.feature +0 -19
- data/plugins/project_search/vendor/lucene/examples/imdb/1_create_neo_db.rb +0 -66
- data/plugins/project_search/vendor/lucene/examples/imdb/2_index_db.rb +0 -23
- data/plugins/project_search/vendor/lucene/examples/imdb/README +0 -12
- data/plugins/project_search/vendor/lucene/examples/imdb/find_actors.rb +0 -56
- data/plugins/project_search/vendor/lucene/examples/imdb/install.sh +0 -12
- data/plugins/project_search/vendor/lucene/examples/imdb/model.rb +0 -37
- data/plugins/project_search/vendor/lucene/examples/railway/README +0 -111
- data/plugins/project_search/vendor/lucene/examples/railway/railnet-app.rb +0 -31
- data/plugins/project_search/vendor/lucene/examples/railway/railnet-data.rb +0 -42
- data/plugins/project_search/vendor/lucene/examples/rest/example.rb +0 -41
- data/plugins/project_search/vendor/lucene/examples/you_might_know/YouMightKnow.java +0 -60
- data/plugins/project_search/vendor/lucene/examples/you_might_know/all_simple_paths.rb +0 -34
- data/plugins/project_search/vendor/lucene/examples/you_might_know/nodes.rb +0 -34
- data/plugins/project_search/vendor/lucene/examples/you_might_know/you_might_know.rb +0 -50
- data/plugins/project_search/vendor/lucene/lib/lucene.rb +0 -15
- data/plugins/project_search/vendor/lucene/lib/lucene/config.rb +0 -145
- data/plugins/project_search/vendor/lucene/lib/lucene/document.rb +0 -96
- data/plugins/project_search/vendor/lucene/lib/lucene/field_info.rb +0 -144
- data/plugins/project_search/vendor/lucene/lib/lucene/hits.rb +0 -54
- data/plugins/project_search/vendor/lucene/lib/lucene/index.rb +0 -267
- data/plugins/project_search/vendor/lucene/lib/lucene/index_info.rb +0 -146
- data/plugins/project_search/vendor/lucene/lib/lucene/index_searcher.rb +0 -157
- data/plugins/project_search/vendor/lucene/lib/lucene/jars.rb +0 -5
- data/plugins/project_search/vendor/lucene/lib/lucene/query_dsl.rb +0 -135
- data/plugins/project_search/vendor/lucene/lib/lucene/transaction.rb +0 -117
- data/plugins/project_search/vendor/lucene/lib/lucene/version.rb +0 -3
- data/plugins/project_search/vendor/lucene/lucene.gemspec +0 -23
- data/plugins/project_search/vendor/lucene/spec/lucene/document_spec.rb +0 -32
- data/plugins/project_search/vendor/lucene/spec/lucene/field_info_spec.rb +0 -70
- data/plugins/project_search/vendor/lucene/spec/lucene/index_info_spec.rb +0 -76
- data/plugins/project_search/vendor/lucene/spec/lucene/index_spec.rb +0 -643
- data/plugins/project_search/vendor/lucene/spec/lucene/query_dsl_spec.rb +0 -142
- data/plugins/project_search/vendor/lucene/spec/lucene/sort_spec.rb +0 -101
- data/plugins/project_search/vendor/lucene/spec/lucene/spec_helper.rb +0 -10
- data/plugins/project_search/vendor/lucene/spec/lucene/transaction_spec.rb +0 -118
@@ -1,60 +0,0 @@
|
|
1
|
-
class YouMightKnow
|
2
|
-
{
|
3
|
-
List<List<Node>> result = new ArrayList<List<Node>>();
|
4
|
-
int maxDistance;
|
5
|
-
String[] features;
|
6
|
-
Object[] values;
|
7
|
-
Set<Node> buddies = new HashSet<Node>();
|
8
|
-
|
9
|
-
YouMightKnow( Node node, String[] features, int maxDistance )
|
10
|
-
{
|
11
|
-
this.features = features;
|
12
|
-
this.maxDistance = maxDistance;
|
13
|
-
values = new Object[features.length];
|
14
|
-
List<Integer> matches = new ArrayList<Integer>();
|
15
|
-
for ( int i = 0; i < features.length; i++ )
|
16
|
-
{
|
17
|
-
values[i] = node.getProperty( features[i] );
|
18
|
-
matches.add( i );
|
19
|
-
}
|
20
|
-
for ( Relationship rel : node.getRelationships( RelationshipTypes.KNOWS ) )
|
21
|
-
{
|
22
|
-
buddies.add( rel.getOtherNode( node ) );
|
23
|
-
}
|
24
|
-
findFriends( Arrays.asList( new Node[] { node } ), matches, 1 );
|
25
|
-
}
|
26
|
-
|
27
|
-
void findFriends( List<Node> path, List<Integer> matches, int depth )
|
28
|
-
{
|
29
|
-
Node prevNode = path.get( path.size() - 1 );
|
30
|
-
for ( Relationship rel : prevNode.getRelationships( RelationshipTypes.KNOWS ) )
|
31
|
-
{
|
32
|
-
Node node = rel.getOtherNode( prevNode );
|
33
|
-
if ( (depth > 1 && buddies.contains( node )) || path.contains( node ) )
|
34
|
-
{
|
35
|
-
continue;
|
36
|
-
}
|
37
|
-
List<Integer> newMatches = new ArrayList<Integer>();
|
38
|
-
for ( int match : matches )
|
39
|
-
{
|
40
|
-
if ( node.getProperty( features[match] ).equals( values[match] ) )
|
41
|
-
{
|
42
|
-
newMatches.add( match );
|
43
|
-
}
|
44
|
-
}
|
45
|
-
if ( newMatches.size() > 0 )
|
46
|
-
{
|
47
|
-
List<Node> newPath = new ArrayList<Node>( path );
|
48
|
-
newPath.add( node );
|
49
|
-
if ( depth > 1 )
|
50
|
-
{
|
51
|
-
result.add( newPath );
|
52
|
-
}
|
53
|
-
if ( depth != maxDistance )
|
54
|
-
{
|
55
|
-
findFriends( newPath, newMatches, depth + 1 );
|
56
|
-
}
|
57
|
-
}
|
58
|
-
}
|
59
|
-
}
|
60
|
-
}
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'neo4j'
|
3
|
-
require 'neo4j/extensions/graph_algo'
|
4
|
-
include Neo4j
|
5
|
-
|
6
|
-
# In this case we want to know the possible paths from one person in a social network to an other.
|
7
|
-
# With those paths at hand we can do things similar to the "How you're connected to N.N." feature of LinkedIn.
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
Transaction.new
|
12
|
-
|
13
|
-
load "nodes.rb"
|
14
|
-
|
15
|
-
node1,node2,node3,node4,node5,node6,node7 = create_nodes
|
16
|
-
|
17
|
-
found_nodes = GraphAlgo.all_simple_paths.from(node1).both(:knows).to(node7).depth(4).as_nodes
|
18
|
-
puts "Nodes between #{node1} and #{node7}"
|
19
|
-
found_nodes.each do |path|
|
20
|
-
puts "path"
|
21
|
-
path.each {|node| puts " #{node}" }
|
22
|
-
end
|
23
|
-
|
24
|
-
sorted = found_nodes.sort_by{|path| 10 - path.size}
|
25
|
-
|
26
|
-
puts "sorted: "
|
27
|
-
sorted.each do |path|
|
28
|
-
puts "path"
|
29
|
-
path.each {|node| puts " #{node}" }
|
30
|
-
end
|
31
|
-
|
32
|
-
Transaction.finish
|
33
|
-
|
34
|
-
Neo4j.stop
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# -----------------------------------------------------------------------------
|
2
|
-
|
3
|
-
# Add a to string method printing the node name
|
4
|
-
class Node
|
5
|
-
include Neo4j::NodeMixin
|
6
|
-
|
7
|
-
def to_s
|
8
|
-
"Node #{self[:name]}"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def create_nodes
|
13
|
-
node1 = Node.new; node1[:feat1] = 'a'; node1[:feat2] = 'b'; node1[:name] = 1
|
14
|
-
node2 = Node.new; node2[:feat1] = 'a'; node2[:feat2] = 'b'; node2[:name] = 2
|
15
|
-
node3 = Node.new; node3[:feat1] = 'a'; node3[:feat2] = 'd'; node3[:name] = 3
|
16
|
-
node4 = Node.new; node4[:feat1] = 'c'; node4[:feat2] = 'd'; node4[:name] = 4
|
17
|
-
node5 = Node.new; node5[:feat1] = 'a'; node5[:feat2] = 'b'; node5[:name] = 5
|
18
|
-
node6 = Node.new; node6[:feat1] = 'a'; node6[:feat2] = 'b'; node6[:name] = 6
|
19
|
-
node7 = Node.new; node7[:feat1] = 'a'; node7[:feat2] = 'b'; node7[:name] = 7
|
20
|
-
|
21
|
-
node1.rels.outgoing(:knows) << node3
|
22
|
-
node2.rels.outgoing(:knows) << node1
|
23
|
-
node2.rels.outgoing(:knows) << node4
|
24
|
-
node3.rels.outgoing(:knows) << node5
|
25
|
-
node3.rels.outgoing(:knows) << node4
|
26
|
-
node3.rels.outgoing(:knows) << node6
|
27
|
-
node4.rels.outgoing(:knows) << node7
|
28
|
-
node5.rels.outgoing(:knows) << node6
|
29
|
-
node5.rels.outgoing(:knows) << node1
|
30
|
-
node6.rels.outgoing(:knows) << node1
|
31
|
-
|
32
|
-
[node1,node2,node3,node4,node5,node6,node7]
|
33
|
-
end
|
34
|
-
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'neo4j'
|
3
|
-
include Neo4j
|
4
|
-
|
5
|
-
|
6
|
-
# The challenge this time is to traverse into friends of friends (or even deeper) and find people with something in common.
|
7
|
-
# Based on this we can distill someone the user might know, or could be interested in knowing.
|
8
|
-
# The persons in our social network all have different values for two features, feat1 and feat2.
|
9
|
-
# The idea of the solution presented here is to keep track of the features that are common in each branch of the traversal
|
10
|
-
# and to stop when there is nothing in common any more or the maximum distance has been reached.
|
11
|
-
def you_might_know(node, matches, max_distance)
|
12
|
-
buddies = [*node.rels.both(:knows).nodes]
|
13
|
-
find_friends(node, [node], matches, 1, max_distance, buddies)
|
14
|
-
end
|
15
|
-
|
16
|
-
def find_friends(root_node, path, matches, depth, max_distance, buddies)
|
17
|
-
result = []
|
18
|
-
path.last.rels.both(:knows).nodes.each do |node|
|
19
|
-
next if (depth > 1 && buddies.include?(node)) || path.include?(node)
|
20
|
-
new_matches = matches.find_all{|feature| root_node[feature] == node[feature]}
|
21
|
-
next if new_matches.empty?
|
22
|
-
new_path = path + [node]
|
23
|
-
result = [new_path] + result if depth > 1
|
24
|
-
result += find_friends(node, new_path, new_matches, depth + 1, max_distance, buddies) if depth != max_distance
|
25
|
-
end
|
26
|
-
result
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
puts "-----------------------"
|
31
|
-
puts "YOU MIGHT KNOW"
|
32
|
-
puts "-----------------------"
|
33
|
-
|
34
|
-
|
35
|
-
Transaction.new
|
36
|
-
|
37
|
-
load "nodes.rb"
|
38
|
-
|
39
|
-
node1,node2,node3,node4,node5,node6,node7 = create_nodes
|
40
|
-
|
41
|
-
result = you_might_know(node5, [:feat1, :feat2], 4)
|
42
|
-
result.each do |list|
|
43
|
-
puts "You might know nodes"
|
44
|
-
list.each {|n| puts n}
|
45
|
-
end
|
46
|
-
|
47
|
-
Transaction.finish
|
48
|
-
Neo4j.stop
|
49
|
-
|
50
|
-
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'logger'
|
2
|
-
$LUCENE_LOGGER = Logger.new(STDOUT)
|
3
|
-
$LUCENE_LOGGER.level = Logger::WARN
|
4
|
-
|
5
|
-
require 'lucene/config'
|
6
|
-
require 'lucene/document'
|
7
|
-
require 'lucene/field_info'
|
8
|
-
require 'lucene/hits'
|
9
|
-
require 'lucene/index'
|
10
|
-
require 'lucene/index_info'
|
11
|
-
require 'lucene/index_searcher'
|
12
|
-
require 'lucene/jars'
|
13
|
-
require 'lucene/query_dsl'
|
14
|
-
require 'lucene/transaction'
|
15
|
-
|
@@ -1,145 +0,0 @@
|
|
1
|
-
|
2
|
-
module Lucene
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
# Keeps configuration for lucene.
|
7
|
-
# Contains both common configuration for all lucene indexes as well
|
8
|
-
# as specific configuration for each index (TODO).
|
9
|
-
# This code is copied from merb-core/config.rb.
|
10
|
-
#
|
11
|
-
# Contains three default configurations (Config.defaults)
|
12
|
-
# * :store_on_file:: default false, which will only keep the index in memory
|
13
|
-
# * :id_field:: default :id
|
14
|
-
# * :storage_path:: where the index is kept on file system if stored as a file (instead of just in memory)
|
15
|
-
#
|
16
|
-
class Config
|
17
|
-
class << self
|
18
|
-
# Returns the hash of default config values for lucene.
|
19
|
-
#
|
20
|
-
# ==== Returns
|
21
|
-
# Hash:: The defaults for the config.
|
22
|
-
#
|
23
|
-
def defaults
|
24
|
-
@defaults ||= {
|
25
|
-
:store_on_file => false,
|
26
|
-
:id_field => :id,
|
27
|
-
:storage_path => nil
|
28
|
-
}
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
# Yields the configuration.
|
33
|
-
#
|
34
|
-
# ==== Block parameters
|
35
|
-
# c<Hash>:: The configuration parameters.
|
36
|
-
#
|
37
|
-
# ==== Examples
|
38
|
-
# Lucene::Config.use do |config|
|
39
|
-
# config[:in_memory] = true
|
40
|
-
# end
|
41
|
-
#
|
42
|
-
# ==== Returns
|
43
|
-
# nil
|
44
|
-
#
|
45
|
-
def use
|
46
|
-
@configuration ||= {}
|
47
|
-
yield @configuration
|
48
|
-
nil
|
49
|
-
end
|
50
|
-
|
51
|
-
|
52
|
-
# Set the value of a config entry.
|
53
|
-
#
|
54
|
-
# ==== Parameters
|
55
|
-
# key<Object>:: The key to set the parameter for.
|
56
|
-
# val<Object>:: The value of the parameter.
|
57
|
-
#
|
58
|
-
def []=(key, val)
|
59
|
-
(@configuration ||= setup)[key] = val
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
# Gets the the value of a config entry
|
64
|
-
#
|
65
|
-
# ==== Parameters
|
66
|
-
# key<Object>:: The key of the config entry value we want
|
67
|
-
#
|
68
|
-
def [](key)
|
69
|
-
(@configuration ||= setup)[key]
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
# Remove the value of a config entry.
|
74
|
-
#
|
75
|
-
# ==== Parameters
|
76
|
-
# key<Object>:: The key of the parameter to delete.
|
77
|
-
#
|
78
|
-
# ==== Returns
|
79
|
-
# Object:: The value of the removed entry.
|
80
|
-
#
|
81
|
-
def delete(key)
|
82
|
-
@configuration.delete(key)
|
83
|
-
end
|
84
|
-
|
85
|
-
|
86
|
-
# Remove all configuration. This can be useful for testing purpose.
|
87
|
-
#
|
88
|
-
#
|
89
|
-
# ==== Returns
|
90
|
-
# nil
|
91
|
-
#
|
92
|
-
def delete_all
|
93
|
-
@configuration = nil
|
94
|
-
IndexInfo.delete_all
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
# Retrieve the value of a config entry, returning the provided default if the key is not present
|
99
|
-
#
|
100
|
-
# ==== Parameters
|
101
|
-
# key<Object>:: The key to retrieve the parameter for.
|
102
|
-
# default<Object>::
|
103
|
-
# The default value to return if the parameter is not set.
|
104
|
-
#
|
105
|
-
# ==== Returns
|
106
|
-
# Object:: The value of the configuration parameter or the default.
|
107
|
-
#
|
108
|
-
def fetch(key, default)
|
109
|
-
@configuration.fetch(key, default)
|
110
|
-
end
|
111
|
-
|
112
|
-
# Sets up the configuration
|
113
|
-
#
|
114
|
-
# ==== Returns
|
115
|
-
# The configuration as a hash.
|
116
|
-
#
|
117
|
-
def setup()
|
118
|
-
@configuration = {}
|
119
|
-
@configuration.merge!(defaults)
|
120
|
-
@configuration
|
121
|
-
end
|
122
|
-
|
123
|
-
|
124
|
-
# Returns the configuration as a hash.
|
125
|
-
#
|
126
|
-
# ==== Returns
|
127
|
-
# Hash:: The config as a hash.
|
128
|
-
#
|
129
|
-
def to_hash
|
130
|
-
@configuration
|
131
|
-
end
|
132
|
-
|
133
|
-
# Returns the config as YAML.
|
134
|
-
#
|
135
|
-
# ==== Returns
|
136
|
-
# String:: The config as YAML.
|
137
|
-
#
|
138
|
-
def to_yaml
|
139
|
-
require "yaml"
|
140
|
-
@configuration.to_yaml
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
module Lucene
|
2
|
-
|
3
|
-
#
|
4
|
-
# A document is like a record or row in a relationship database.
|
5
|
-
# Contains the field infos which can be used for type conversions or
|
6
|
-
# specifying if the field should be stored or only searchable.
|
7
|
-
#
|
8
|
-
class Document
|
9
|
-
|
10
|
-
attr_reader :id_field, :field_infos, :props
|
11
|
-
|
12
|
-
def initialize(field_infos, props = {})
|
13
|
-
@id_field = field_infos.id_field
|
14
|
-
@field_infos = field_infos
|
15
|
-
|
16
|
-
@props = {}
|
17
|
-
props.each_pair do |key,value|
|
18
|
-
@props[key] = field_infos[key].convert_to_ruby(value)
|
19
|
-
$LUCENE_LOGGER.debug{"FieldInfo #{key} type: #{field_infos[key][:type]}"}
|
20
|
-
$LUCENE_LOGGER.debug{"Converted #{key} '#{value}' type: '#{value.class.to_s}' to '#{@props[key]}' type: '#{@props[key].class.to_s}'"}
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def [](key)
|
25
|
-
@props[key]
|
26
|
-
end
|
27
|
-
|
28
|
-
#
|
29
|
-
# Convert a java Document to a ruby Lucene::Document
|
30
|
-
#
|
31
|
-
def self.convert(field_infos, java_doc)
|
32
|
-
fields = {}
|
33
|
-
field_infos.each_pair do |key, field|
|
34
|
-
next unless field.store?
|
35
|
-
raise StandardError.new("expected field '#{key.to_s}' to exist in document") if java_doc.getField(key.to_s).nil?
|
36
|
-
value = java_doc.getField(key.to_s).stringValue
|
37
|
-
fields.merge!({key => value})
|
38
|
-
end
|
39
|
-
Document.new(field_infos, fields)
|
40
|
-
end
|
41
|
-
|
42
|
-
def id
|
43
|
-
raise IdFieldMissingException.new("Missing id field: '#{@id_field}'") if self[@id_field].nil?
|
44
|
-
@props[@id_field]
|
45
|
-
end
|
46
|
-
|
47
|
-
def eql?(other)
|
48
|
-
return false unless other.is_a? Document
|
49
|
-
return id == other.id
|
50
|
-
end
|
51
|
-
|
52
|
-
def ==(other)
|
53
|
-
eql?(other)
|
54
|
-
end
|
55
|
-
|
56
|
-
def hash
|
57
|
-
id.hash
|
58
|
-
end
|
59
|
-
|
60
|
-
#
|
61
|
-
# removes the document and adds it again
|
62
|
-
#
|
63
|
-
def update(index_writer)
|
64
|
-
index_writer.updateDocument(java_key_term, java_document)
|
65
|
-
end
|
66
|
-
|
67
|
-
|
68
|
-
def java_key_term
|
69
|
-
org.apache.lucene.index.Term.new(@id_field.to_s, id.to_s)
|
70
|
-
end
|
71
|
-
|
72
|
-
def java_document
|
73
|
-
java_doc = org.apache.lucene.document.Document.new
|
74
|
-
@props.each_pair do |key,value|
|
75
|
-
field_info = @field_infos[key]
|
76
|
-
# TODO value could be an array if value.kind_of? Enumerable
|
77
|
-
if (value.kind_of?(Array))
|
78
|
-
value.each do |v|
|
79
|
-
field = field_info.java_field(key,v)
|
80
|
-
java_doc.add(field) unless field.nil?
|
81
|
-
end
|
82
|
-
else
|
83
|
-
field = field_info.java_field(key,value)
|
84
|
-
java_doc.add(field) unless field.nil?
|
85
|
-
end
|
86
|
-
end
|
87
|
-
java_doc
|
88
|
-
end
|
89
|
-
|
90
|
-
def to_s
|
91
|
-
p = ""
|
92
|
-
@props.each_pair { |key,value| p << "'#{key}' = '#{value}' " }
|
93
|
-
"Document [#@id_field='#{self[@id_field]}', #{p}]"
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,144 +0,0 @@
|
|
1
|
-
require 'date'
|
2
|
-
|
3
|
-
module Lucene
|
4
|
-
class ConversionNotSupportedException < StandardError; end
|
5
|
-
|
6
|
-
class FieldInfo
|
7
|
-
DEFAULTS = {:store => false, :type => String, :analyzer => :standard}.freeze
|
8
|
-
|
9
|
-
def initialize(values = {})
|
10
|
-
@info = DEFAULTS.dup
|
11
|
-
@info.merge! values
|
12
|
-
$LUCENE_LOGGER.debug{"new FieldInfo: #{@info.inspect}"}
|
13
|
-
end
|
14
|
-
|
15
|
-
def dup
|
16
|
-
FieldInfo.new(@info)
|
17
|
-
end
|
18
|
-
|
19
|
-
def [](key)
|
20
|
-
@info[key]
|
21
|
-
end
|
22
|
-
|
23
|
-
def []=(key,value)
|
24
|
-
@info[key] = value
|
25
|
-
end
|
26
|
-
|
27
|
-
def java_field(key, value)
|
28
|
-
# convert the ruby value to a string that lucene can handle
|
29
|
-
cvalue = convert_to_lucene(value)
|
30
|
-
|
31
|
-
# check if this field should be indexed
|
32
|
-
return nil if cvalue.nil?
|
33
|
-
|
34
|
-
# decide if the field should be stored in the lucene index or not
|
35
|
-
store = store? ? org.apache.lucene.document.Field::Store::YES : org.apache.lucene.document.Field::Store::NO
|
36
|
-
|
37
|
-
# decide if it should be tokenized/analyzed by lucene
|
38
|
-
token_type = tokenized? ? org.apache.lucene.document.Field::Index::ANALYZED : org.apache.lucene.document.Field::Index::NOT_ANALYZED
|
39
|
-
$LUCENE_LOGGER.debug{"java_field store=#{store} key='#{key.to_s}' value='#{cvalue}' token_type=#{token_type}"}
|
40
|
-
|
41
|
-
# create the new Field
|
42
|
-
org.apache.lucene.document.Field.new(key.to_s, cvalue, store, token_type ) #org.apache.lucene.document.Field::Index::NO_NORMS)
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
def convert_to_ruby(value)
|
47
|
-
if (value.kind_of?(Array))
|
48
|
-
value.collect{|v| convert_to_ruby(v)}
|
49
|
-
else case @info[:type].to_s
|
50
|
-
when NilClass.to_s then "" # TODO, should we accept nil values in indexes ?
|
51
|
-
when String.to_s then value.to_s
|
52
|
-
when Fixnum.to_s then value.to_i
|
53
|
-
when Float.to_s then value.to_f
|
54
|
-
when Date.to_s
|
55
|
-
return value if value.kind_of? Date
|
56
|
-
return nil if value.nil?
|
57
|
-
year = value[0..3].to_i
|
58
|
-
month = value[4..5].to_i
|
59
|
-
day = value[6..7].to_i
|
60
|
-
Date.new year,month,day
|
61
|
-
when DateTime.to_s
|
62
|
-
return value if value.kind_of? DateTime
|
63
|
-
return nil if value.nil?
|
64
|
-
year = value[0..3].to_i
|
65
|
-
month = value[4..5].to_i
|
66
|
-
day = value[6..7].to_i
|
67
|
-
hour = value[8..9].to_i
|
68
|
-
min = value[10..11].to_i
|
69
|
-
sec = value[12..13].to_i
|
70
|
-
DateTime.civil(year,month,day,hour,min,sec)
|
71
|
-
else
|
72
|
-
raise ConversionNotSupportedException.new("Can't convert key '#{value}' of with type '#{@info[:type].class.to_s}'")
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def convert_to_lucene(value)
|
78
|
-
if (value.kind_of?(Array))
|
79
|
-
value.collect{|v| convert_to_lucene(v)}
|
80
|
-
elsif value.nil?
|
81
|
-
value
|
82
|
-
else
|
83
|
-
case @info[:type].to_s # otherwise it will match Class
|
84
|
-
when Fixnum.to_s then sprintf('%011d',value) # TODO: configurable
|
85
|
-
when Float.to_s then sprintf('%024.12f', value) # TODO: configurable
|
86
|
-
when Bignum.to_s then sprintf('%024d, value')
|
87
|
-
when Date.to_s
|
88
|
-
t = Time.utc(value.year, value.month, value.day)
|
89
|
-
d = t.to_i * 1000
|
90
|
-
org.apache.lucene.document.DateTools.timeToString(d,org.apache.lucene.document.DateTools::Resolution::DAY )
|
91
|
-
when DateTime.to_s
|
92
|
-
# only utc times are supported
|
93
|
-
t = Time.utc(value.year, value.month, value.day, value.hour, value.min, value.sec)
|
94
|
-
d = t.to_i * 1000
|
95
|
-
org.apache.lucene.document.DateTools.timeToString(d,org.apache.lucene.document.DateTools::Resolution::SECOND )
|
96
|
-
else value.to_s
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def convert_to_query(key,value)
|
102
|
-
if (value.kind_of? Range)
|
103
|
-
first_value = convert_to_lucene(value.first)
|
104
|
-
last_value = convert_to_lucene(value.last)
|
105
|
-
first = org.apache.lucene.index.Term.new(key.to_s, first_value)
|
106
|
-
last = org.apache.lucene.index.Term.new(key.to_s, last_value)
|
107
|
-
$LUCENE_LOGGER.debug{"convert_to_query: Range key '#{key.to_s}' #{first_value}' to '#{last_value}'"}
|
108
|
-
org.apache.lucene.search.RangeQuery.new(first, last, !value.exclude_end?)
|
109
|
-
elsif
|
110
|
-
converted_value = convert_to_lucene(value)
|
111
|
-
term = org.apache.lucene.index.Term.new(key.to_s, converted_value)
|
112
|
-
org.apache.lucene.search.TermQuery.new(term)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def tokenized?
|
117
|
-
@info[:tokenized]
|
118
|
-
end
|
119
|
-
|
120
|
-
def store?
|
121
|
-
@info[:store]
|
122
|
-
end
|
123
|
-
|
124
|
-
def eql?(other)
|
125
|
-
return false unless other.kind_of?(FieldInfo)
|
126
|
-
@info.each_pair do |key,value|
|
127
|
-
return false if other[key] != value
|
128
|
-
end
|
129
|
-
return true
|
130
|
-
end
|
131
|
-
|
132
|
-
def ==(other)
|
133
|
-
eql? other
|
134
|
-
end
|
135
|
-
|
136
|
-
def to_s
|
137
|
-
infos = @info.keys.inject(""){|s, key| s << "#{key}=#{@info[key]} "}
|
138
|
-
"FieldInfo(#{self.object_id.to_s}) [#{infos}]"
|
139
|
-
end
|
140
|
-
|
141
|
-
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|