redcar 0.9.0 → 0.9.1

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.
Files changed (63) hide show
  1. data/CHANGES +5 -0
  2. data/Rakefile +1 -2
  3. data/lib/redcar/installer.rb +2 -1
  4. data/lib/redcar.rb +2 -2
  5. data/plugins/project_search/vendor/lucene/CHANGELOG +147 -0
  6. data/plugins/project_search/vendor/lucene/CONTRIBUTORS +17 -0
  7. data/plugins/project_search/vendor/lucene/Gemfile +9 -0
  8. data/plugins/project_search/vendor/lucene/Gemfile.lock +33 -0
  9. data/plugins/project_search/vendor/lucene/LICENSE +19 -0
  10. data/plugins/project_search/vendor/lucene/README.rdoc +283 -0
  11. data/plugins/project_search/vendor/lucene/Rakefile +35 -0
  12. data/plugins/project_search/vendor/lucene/examples/active_model/serializers.rb +25 -0
  13. data/plugins/project_search/vendor/lucene/examples/active_model/validation.rb +26 -0
  14. data/plugins/project_search/vendor/lucene/examples/admin/Rakefile +4 -0
  15. data/plugins/project_search/vendor/lucene/examples/admin/admin.rb +29 -0
  16. data/plugins/project_search/vendor/lucene/examples/admin/public/jquery.js +4376 -0
  17. data/plugins/project_search/vendor/lucene/examples/admin/public/neo4j.css +153 -0
  18. data/plugins/project_search/vendor/lucene/examples/admin/public/neo_admin.js +18 -0
  19. data/plugins/project_search/vendor/lucene/examples/admin/spec/admin_spec.rb +26 -0
  20. data/plugins/project_search/vendor/lucene/examples/admin/views/index.erb +21 -0
  21. data/plugins/project_search/vendor/lucene/examples/filetree/README.rdoc +9 -0
  22. data/plugins/project_search/vendor/lucene/examples/filetree/app.rb +7 -0
  23. data/plugins/project_search/vendor/lucene/examples/filetree/batch.props +5 -0
  24. data/plugins/project_search/vendor/lucene/examples/filetree/features/step_definitions/add_steps.rb +121 -0
  25. data/plugins/project_search/vendor/lucene/examples/filetree/features/support/env.rb +30 -0
  26. data/plugins/project_search/vendor/lucene/examples/filetree/features/support/rspec_helper.rb +50 -0
  27. data/plugins/project_search/vendor/lucene/examples/filetree/features/treesizes.feature +19 -0
  28. data/plugins/project_search/vendor/lucene/examples/imdb/1_create_neo_db.rb +66 -0
  29. data/plugins/project_search/vendor/lucene/examples/imdb/2_index_db.rb +23 -0
  30. data/plugins/project_search/vendor/lucene/examples/imdb/README +12 -0
  31. data/plugins/project_search/vendor/lucene/examples/imdb/find_actors.rb +56 -0
  32. data/plugins/project_search/vendor/lucene/examples/imdb/install.sh +12 -0
  33. data/plugins/project_search/vendor/lucene/examples/imdb/model.rb +37 -0
  34. data/plugins/project_search/vendor/lucene/examples/railway/README +111 -0
  35. data/plugins/project_search/vendor/lucene/examples/railway/railnet-app.rb +31 -0
  36. data/plugins/project_search/vendor/lucene/examples/railway/railnet-data.rb +42 -0
  37. data/plugins/project_search/vendor/lucene/examples/rest/example.rb +41 -0
  38. data/plugins/project_search/vendor/lucene/examples/you_might_know/YouMightKnow.java +60 -0
  39. data/plugins/project_search/vendor/lucene/examples/you_might_know/all_simple_paths.rb +34 -0
  40. data/plugins/project_search/vendor/lucene/examples/you_might_know/nodes.rb +34 -0
  41. data/plugins/project_search/vendor/lucene/examples/you_might_know/you_might_know.rb +50 -0
  42. data/plugins/project_search/vendor/lucene/lib/lucene/config.rb +145 -0
  43. data/plugins/project_search/vendor/lucene/lib/lucene/document.rb +96 -0
  44. data/plugins/project_search/vendor/lucene/lib/lucene/field_info.rb +144 -0
  45. data/plugins/project_search/vendor/lucene/lib/lucene/hits.rb +54 -0
  46. data/plugins/project_search/vendor/lucene/lib/lucene/index.rb +267 -0
  47. data/plugins/project_search/vendor/lucene/lib/lucene/index_info.rb +146 -0
  48. data/plugins/project_search/vendor/lucene/lib/lucene/index_searcher.rb +157 -0
  49. data/plugins/project_search/vendor/lucene/lib/lucene/jars.rb +5 -0
  50. data/plugins/project_search/vendor/lucene/lib/lucene/query_dsl.rb +135 -0
  51. data/plugins/project_search/vendor/lucene/lib/lucene/transaction.rb +117 -0
  52. data/plugins/project_search/vendor/lucene/lib/lucene/version.rb +3 -0
  53. data/plugins/project_search/vendor/lucene/lib/lucene.rb +15 -0
  54. data/plugins/project_search/vendor/lucene/lucene.gemspec +23 -0
  55. data/plugins/project_search/vendor/lucene/spec/lucene/document_spec.rb +32 -0
  56. data/plugins/project_search/vendor/lucene/spec/lucene/field_info_spec.rb +70 -0
  57. data/plugins/project_search/vendor/lucene/spec/lucene/index_info_spec.rb +76 -0
  58. data/plugins/project_search/vendor/lucene/spec/lucene/index_spec.rb +643 -0
  59. data/plugins/project_search/vendor/lucene/spec/lucene/query_dsl_spec.rb +142 -0
  60. data/plugins/project_search/vendor/lucene/spec/lucene/sort_spec.rb +101 -0
  61. data/plugins/project_search/vendor/lucene/spec/lucene/spec_helper.rb +10 -0
  62. data/plugins/project_search/vendor/lucene/spec/lucene/transaction_spec.rb +118 -0
  63. metadata +62 -4
@@ -0,0 +1,157 @@
1
+ module Lucene
2
+
3
+ class Asc
4
+ class << self
5
+
6
+ # Specifies which fields should be sorted in ascending order
7
+ #
8
+ # ==== Parameters
9
+ # fields:: One or more fields to sort in ascending order (Array)
10
+ #
11
+ # ==== Examples
12
+ # Asc[:name, :age]
13
+ #
14
+ # ==== Returns
15
+ # An array of sort fields
16
+ #
17
+ def [](*fields)
18
+ fields.map{|x| org.apache.lucene.search.SortField.new(x.to_s)}
19
+ end
20
+ end
21
+ end
22
+
23
+ class Desc
24
+ class << self
25
+ # Specifies which fields should be sorted in descending order
26
+ #
27
+ # ==== Block parameters
28
+ # fields:: One or more fields to sort in descending order (Array)
29
+ #
30
+ # ==== Examples
31
+ # Desc[:name, :age]
32
+ #
33
+ # ==== Returns
34
+ # An array of sort fields
35
+ #
36
+ def [](*fields)
37
+ fields.map{|x| org.apache.lucene.search.SortField.new(x.to_s, true)}
38
+ #org.apache.lucene.search.Sort.new(values.map{|x| org.apache.lucene.search.SortField.new(x.to_s, true)}.to_java(:'org.apache.lucene.search.SortField'))
39
+ end
40
+ end
41
+ end
42
+
43
+ #
44
+ # Does reuse Lucene Index Search for the same index.
45
+ # Reloads the index if the index has changed.
46
+ #
47
+ class IndexSearcher
48
+
49
+ @@paths = {}
50
+
51
+ def initialize(path)
52
+ @path = path
53
+ end
54
+
55
+ #
56
+ # Only create a new object if it does not already exist for this path
57
+ #
58
+ def self.new(path)
59
+ @@paths[path] = super(path) if @@paths[path].nil?
60
+ @@paths[path]
61
+ end
62
+
63
+ def find_dsl(field_infos,&block)
64
+ exp = QueryDSL.parse(&block)
65
+ query = exp.to_lucene(field_infos)
66
+
67
+ Hits.new(field_infos, index_searcher.search(query))
68
+ end
69
+
70
+
71
+ def find(field_info, query)
72
+ # are there any index for this node ?
73
+ # if not return an empty array
74
+ return [] unless exist?
75
+
76
+ #puts "QUERY #{query.inspect}" # '#{query.first.class.to_s}' value #{query.first}"
77
+ sort_by ||= query[1].delete(:sort_by) if query[1].kind_of?(Hash)
78
+ sort_by ||= query.delete(:sort_by)
79
+ #puts "QUERY sort #{sort_by}"
80
+ # TODO Refactoring ! too long and complex method
81
+ lucene_query = case query
82
+ when Array
83
+ sort_by ||= query.last.delete(:sort_by) if query.last.kind_of?(Hash)
84
+ parser = org.apache.lucene.queryParser.QueryParser.new(field_info.id_field.to_s, field_info.analyzer)
85
+ parser.parse(query.first)
86
+ when Hash
87
+ bquery = org.apache.lucene.search.BooleanQuery.new
88
+ query.each_pair do |key,value|
89
+ field = field_info[key]
90
+ q = field.convert_to_query(key, value)
91
+ bquery.add(q, org.apache.lucene.search.BooleanClause::Occur::MUST)
92
+ end
93
+ bquery
94
+ else
95
+ raise StandardError.new("Unknown type #{query.class.to_s} for find #{query}")
96
+ end
97
+
98
+ if sort_by.nil?
99
+ Hits.new(field_info, index_searcher.search(lucene_query))
100
+ else
101
+ sort = create_sort(sort_by)
102
+ Hits.new(field_info, index_searcher.search(lucene_query, sort))
103
+ end
104
+
105
+ end
106
+
107
+ def parse_field(field)
108
+ case field
109
+ when String,Symbol
110
+ [org.apache.lucene.search.SortField.new(field.to_s)]
111
+ when org.apache.lucene.search.SortField
112
+ [field]
113
+ when Array
114
+ raise StandardError.new("Unknown sort field '#{field}'") unless field.first.kind_of?(org.apache.lucene.search.SortField)
115
+ field
116
+ end
117
+ end
118
+
119
+
120
+ def create_sort(fields)
121
+ case fields
122
+ when String,Symbol
123
+ org.apache.lucene.search.Sort.new(fields.to_s)
124
+ when org.apache.lucene.search.SortField
125
+ org.apache.lucene.search.Sort.new(fields)
126
+ when Array
127
+ sorts = []
128
+ fields.each do |field|
129
+ sorts += parse_field(field)
130
+ end
131
+ org.apache.lucene.search.Sort.new(sorts.to_java(:'org.apache.lucene.search.SortField'))
132
+ else
133
+ StandardError.new("Unknown type #{fields.class.to_s}")
134
+ end
135
+ end
136
+
137
+ #
138
+ # Checks if it needs to reload the index searcher
139
+ #
140
+ def index_searcher
141
+ if @index_reader.nil? || @index_reader.getVersion() != org.apache.lucene.index.IndexReader.getCurrentVersion(@path)
142
+ @index_reader = org.apache.lucene.index.IndexReader.open(@path)
143
+ @index_searcher = org.apache.lucene.search.IndexSearcher.new(@index_reader)
144
+ $LUCENE_LOGGER.debug("Opened new IndexSearcher for #{to_s}")
145
+ end
146
+ @index_searcher
147
+ end
148
+
149
+ #
150
+ # Returns true if the index already exists.
151
+ #
152
+ def exist?
153
+ org.apache.lucene.index.IndexReader.index_exists(@path)
154
+ end
155
+
156
+ end
157
+ end
@@ -0,0 +1,5 @@
1
+ include Java
2
+
3
+ module Lucene
4
+ require 'lucene/jars/lucene-core-2.9.1.jar'
5
+ end
@@ -0,0 +1,135 @@
1
+ module Lucene
2
+
3
+ class Expression #:nodoc:
4
+ attr_accessor :left, :right, :op, :query
5
+
6
+ def self.new_complete(left, op, right)
7
+ expr = Expression.new
8
+ expr.left = left
9
+ expr.op = op
10
+ expr.right = right
11
+ expr
12
+ end
13
+
14
+ def self.new_uncomplete(left, query)
15
+ expr = Expression.new
16
+ expr.left = left
17
+ expr.query = query
18
+ expr
19
+ end
20
+
21
+ def ==(other)
22
+ @op = :==
23
+ @right = other
24
+ @query
25
+ end
26
+
27
+ def >(other)
28
+ @op = :>
29
+ @right = other
30
+ @query
31
+ end
32
+
33
+ #
34
+ # Returns the fields being used in a query
35
+ #
36
+ def _fields(fields = [])
37
+ if (@left.kind_of? Expression)
38
+ @left._fields(fields)
39
+ else
40
+ fields << @left
41
+ end
42
+ if (@right.kind_of? Expression)
43
+ @right._fields(fields)
44
+ end
45
+ fields
46
+ end
47
+
48
+ def to_lucene(field_infos)
49
+ $LUCENE_LOGGER.debug{"QueryDSL.to_lucene '#{to_s}'"}
50
+
51
+ if @left.kind_of? Lucene::Expression
52
+ left_query = @left.to_lucene(field_infos)
53
+ raise ArgumentError.new("Right term is not an Expression, but a '#{@right.class.to_s}'") unless @right.kind_of? Lucene::Expression
54
+ right_query = @right.to_lucene(field_infos)
55
+ query = org.apache.lucene.search.BooleanQuery.new
56
+ clause = (@op == :&) ? org.apache.lucene.search.BooleanClause::Occur::MUST : org.apache.lucene.search.BooleanClause::Occur::SHOULD
57
+ query.add(left_query, clause)
58
+ query.add(right_query, clause)
59
+ return query
60
+ else
61
+ field_info = field_infos[@left]
62
+ field_info.convert_to_query(@left, @right)
63
+ end
64
+ end
65
+
66
+ def to_s
67
+ "(#@left #@op #@right)"
68
+ end
69
+ end
70
+
71
+ class QueryDSL
72
+ attr_reader :stack
73
+
74
+ def initialize
75
+ @stack = []
76
+ #yield self
77
+ end
78
+
79
+ def self.find(field_infos = IndexInfo.new(:id), &expr)
80
+ exp = QueryDSL.parse(&expr)
81
+ exp.to_lucene(field_infos)
82
+ end
83
+
84
+
85
+
86
+ def self.parse(&query)
87
+ query_dsl = QueryDSL.new
88
+ query_dsl.instance_eval(&query)
89
+ query_dsl.stack.last
90
+ end
91
+
92
+ def method_missing(methodname, *args)
93
+ expr = Expression.new_uncomplete(methodname, self)
94
+ @stack.push expr
95
+ expr
96
+ end
97
+
98
+ def ==(other)
99
+ puts "WRONG == '#{other}'"
100
+ end
101
+
102
+ def <=>(to)
103
+ from = @stack.last.right
104
+ @stack.last.right = Range.new(from, to)
105
+ @stack.last
106
+ end
107
+
108
+
109
+ def &(other)
110
+ raise ArgumentError.new("Expected at least two expression on stack, got #{@stack.size}") if @stack.size < 2
111
+ right = @stack.pop
112
+ left = @stack.pop
113
+ expr = Expression.new_complete(left, :&, right)
114
+ @stack.push expr
115
+ self
116
+ end
117
+
118
+ def |(other)
119
+ raise ArgumentError.new("Expected at least two expression on stack, got #{@stack.size}") if @stack.size < 2
120
+ right = @stack.pop
121
+ left = @stack.pop
122
+ expr = Expression.new_complete(left, :|, right)
123
+ @stack.push expr
124
+ self
125
+ end
126
+
127
+ def to_s
128
+ @stack.last.to_s
129
+ end
130
+
131
+ end
132
+
133
+
134
+ end
135
+
@@ -0,0 +1,117 @@
1
+ module Lucene
2
+
3
+ class TransactionAlreadyRunningException < StandardError; end
4
+ class TransactionNotRunningException < StandardError; end
5
+
6
+ class Transaction
7
+
8
+ def initialize
9
+ raise TransactionAlreadyRunningException.new if Transaction.running?
10
+ Thread.current[:lucene_transaction] = self
11
+
12
+ @rollback = false
13
+ @commited = false
14
+ @indexes = {} # key is the path to index, value is the index instance
15
+ end
16
+
17
+ def to_s
18
+ "Transaction [commited=#@commited, rollback=#@rollback, indexes=#{@indexes.size}, object_id=#{object_id}]"
19
+ end
20
+
21
+
22
+ # Commits all registered Indexes.
23
+ # Stops this transaction (running? will be false)
24
+ #
25
+ def commit
26
+ if !@rollback
27
+ @indexes.each_value do |index|
28
+ index.commit
29
+ end
30
+ end
31
+ @commited = true
32
+ @indexes.clear
33
+ Thread.current[:lucene_transaction] = nil
34
+ end
35
+
36
+ def failure
37
+ @rollback = true
38
+ $LUCENE_LOGGER.debug{"Rollback Lucene Transaction"}
39
+ end
40
+
41
+ def rollback?
42
+ @rollback
43
+ end
44
+
45
+ def rollback!
46
+ @rollback = true
47
+ end
48
+
49
+ #
50
+ # Registers an index to take part of this transaction
51
+ #
52
+ def register_index(key, index)
53
+ @indexes[key] = index
54
+ $LUCENE_LOGGER.debug{"Registered index for #{index}"}
55
+ end
56
+
57
+ #
58
+ # Deregister the index so that it will not be part of the transaction
59
+ # any longer.
60
+ #
61
+ def deregister_index(index)
62
+ @indexes.delete index.path
63
+ $LUCENE_LOGGER.debug{"Deregistered index for #{index}"}
64
+ end
65
+
66
+ #
67
+ # Deregister all indexes, used for testing purpose.
68
+ #
69
+ def deregister_all_indexes
70
+ @indexes.clear
71
+ $LUCENE_LOGGER.debug{"Deregistered all index, #{@indexes.inspect}"}
72
+ end
73
+
74
+
75
+ def index?(path)
76
+ @indexes[path] != nil
77
+ end
78
+
79
+ def index(path)
80
+ @indexes[path]
81
+ end
82
+
83
+ #
84
+ # Class methods
85
+ #
86
+ class << self
87
+ def run
88
+ tx = Transaction.new
89
+ begin
90
+ yield tx
91
+ rescue => ex
92
+ tx.failure
93
+ # TODO reuse of error handling and logging
94
+ $LUCENE_LOGGER.error{"Got exception #{ex}"}
95
+ ex.backtrace.each {|t| $LUCENE_LOGGER.error(t)}
96
+ raise
97
+ ensure
98
+ tx.commit unless tx.rollback?
99
+ end
100
+ end
101
+
102
+ #
103
+ # Returns the current transaction or nil
104
+ #
105
+ def current
106
+ Thread.current[:lucene_transaction]
107
+ end
108
+
109
+
110
+ def running?
111
+ self.current != nil
112
+ end
113
+ end
114
+ end
115
+
116
+
117
+ end
@@ -0,0 +1,3 @@
1
+ module Lucene
2
+ VERSION = '0.5.0.beta.1'
3
+ end
@@ -0,0 +1,15 @@
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
+
@@ -0,0 +1,23 @@
1
+ lib = File.expand_path('../lib/', __FILE__)
2
+ $:.unshift lib unless $:.include?(lib)
3
+
4
+ require 'lucene/version'
5
+
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "lucene"
9
+ s.version = Lucene::VERSION
10
+ # s.platform = Gem::Platform::CURRENT # will probably support C Ruby via RJB also in the future
11
+ s.authors = "Andreas Ronge"
12
+ s.email = 'andreas.ronge@gmail.com'
13
+ s.homepage = "http://github.com/andreasronge/lucene/tree"
14
+ s.rubyforge_project = 'lucene'
15
+ s.summary = "A lucene wrapper for JRuby"
16
+ s.description = s.summary
17
+ s.require_path = 'lib'
18
+ s.files = Dir.glob("{bin,lib}/**/*") + %w(README.rdoc CHANGELOG CONTRIBUTORS Gemfile lucene.gemspec)
19
+ s.has_rdoc = true
20
+ s.extra_rdoc_files = %w( README.rdoc )
21
+ s.rdoc_options = ["--quiet", "--title", "Lucene.rb", "--opname", "index.html", "--line-numbers", "--main", "README.rdoc", "--inline-source"]
22
+ s.required_ruby_version = ">= 1.8.7"
23
+ end
@@ -0,0 +1,32 @@
1
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/../../lib")
2
+ require 'lucene'
3
+
4
+ include Lucene
5
+
6
+ describe Document do
7
+ before(:all) do
8
+ @infos = IndexInfo.new(:my_id)
9
+ @infos[:value] = {:type => Float}
10
+ end
11
+
12
+ it "should have field infos" do
13
+ doc = Document.new(@infos)
14
+ doc.field_infos.should be_equal(@infos)
15
+ end
16
+
17
+ it "should convert fields" do
18
+ #$LUCENE_LOGGER.level = Logger::DEBUG
19
+ doc = Document.new(@infos, {:my_id => 1, :value => '1.23'})
20
+ doc[:my_id].should be_kind_of(String)
21
+ doc[:value].should be_kind_of(Float)
22
+ doc[:my_id].should == "1"
23
+ doc[:value].should == 1.23
24
+ #$LUCENE_LOGGER.level = Logger::WARN
25
+ end
26
+
27
+ it "should handle multiple fields with the same id" do
28
+ doc = Document.new(@infos, {:my_id => 1, :name => ['abc', 'def', '123']})
29
+ doc[:name].should == ['abc', 'def', '123']
30
+ end
31
+ end
32
+
@@ -0,0 +1,70 @@
1
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/../../lib")
2
+ require 'lucene'
3
+
4
+ include Lucene
5
+
6
+ describe FieldInfo do
7
+ it "should have default values" do
8
+ f = FieldInfo.new({})
9
+ f.store?.should == false
10
+ f[:store].should == false
11
+ f[:type].should == String
12
+ end
13
+
14
+ it "should be possible to override default values" do
15
+ f = FieldInfo.new(:store => true)
16
+ f.store?.should == true
17
+ end
18
+
19
+ it "should be possible to set any field" do
20
+ f = FieldInfo.new(:store => true, :foo => 1, :bar=>2)
21
+ f[:foo].should == 1
22
+ f[:bar].should == 2
23
+ end
24
+
25
+ it "should handle dup - create a new copy of it" do
26
+ f1 = FieldInfo.new(:store => true, :foo => 1, :bar=>2)
27
+ f1.freeze
28
+ f2 = f1.dup
29
+ f2[:store] = false
30
+ f1[:store].should be_true
31
+ f2[:store].should be_false
32
+ end
33
+
34
+ it "should handle conversion of arrays" do
35
+ f = FieldInfo.new
36
+ c = f.convert_to_lucene(['a','b','c'])
37
+ c.should == ['a', 'b', 'c']
38
+ end
39
+
40
+ it "should handle conversion of arrays and each value should be converted to correct type" do
41
+ f = FieldInfo.new
42
+ f[:type] = Fixnum
43
+ c = f.convert_to_lucene(['1','2','3'])
44
+ c.should == ["00000000001", "00000000002", "00000000003"]
45
+ end
46
+
47
+ it "should convert to correct ruby type from a lucene string value" do
48
+ f = FieldInfo.new
49
+ f[:type] = Fixnum
50
+ f.convert_to_ruby("123").should == 123
51
+ end
52
+
53
+ it "should convert Dates to lucene" do
54
+ f = FieldInfo.new
55
+ f[:type] = Date
56
+ f.convert_to_lucene(Date.new(2008,12,15)).should == "20081215"
57
+ end
58
+
59
+ it "should convert Dates from lucene" do
60
+ f = FieldInfo.new
61
+ f[:type] = Date
62
+ d = f.convert_to_ruby('20081215')
63
+ d.should be_instance_of(Date)
64
+ d.year.should == 2008
65
+ d.month.should == 12
66
+ d.day.should == 15
67
+ end
68
+
69
+ end
70
+
@@ -0,0 +1,76 @@
1
+ $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/../../lib")
2
+ require 'lucene'
3
+
4
+ include Lucene
5
+
6
+ describe IndexInfo do
7
+ it "should have an id_field" do
8
+ f = IndexInfo.new('path')
9
+ f.id_field = :my_id
10
+ f.id_field.should == :my_id
11
+ end
12
+
13
+ it "should have a default for any key" do
14
+ f = IndexInfo.new('some_path')
15
+ f[42].should == IndexInfo::DEFAULTS
16
+ IndexInfo::DEFAULTS[:store].should == false
17
+ f[42][:store].should == false
18
+ end
19
+
20
+ it "can set a field by a hash of infos " do
21
+ # given
22
+ f = IndexInfo.new('some_path')
23
+ # when
24
+ f[:value] = {:type => Float}
25
+ # then
26
+ f[:value].should be_kind_of(FieldInfo)
27
+ f[:value][:type].should == Float
28
+ end
29
+
30
+ it "can set a field by a FieldInfo" do
31
+ # given
32
+ f = IndexInfo.new('some_path')
33
+ # when
34
+ f[:value] = FieldInfo.new(:type => Float)
35
+ # then
36
+ f[:value].should be_kind_of(FieldInfo)
37
+ f[:value][:type].should == Float
38
+ end
39
+
40
+ it "can set a individual property of a FieldInfo" do
41
+ # given
42
+ f = IndexInfo.new('some_path')
43
+
44
+ # when
45
+ f[:value][:type] = Float
46
+
47
+ # then
48
+ f[:value].should be_kind_of(FieldInfo)
49
+ f[:value][:type].should == Float
50
+ end
51
+
52
+ it "can set several individual properties of a FieldInfo" do
53
+ # given
54
+ f = IndexInfo.new('some_path')
55
+
56
+ # when
57
+ f[:value][:type] = Float
58
+ f[:foo][:type] = Fixnum
59
+ f[:value][:bar] = 42
60
+
61
+ # then
62
+ f[:value].object_id.should_not == f[:foo].object_id
63
+
64
+ f[:value][:type].should == Float
65
+ f[:foo][:type].should == Fixnum
66
+ f[:value][:bar].should == 42
67
+ end
68
+
69
+ end
70
+
71
+ describe "IndexInfo::DEFAULTS" do
72
+ it "should have default values" do
73
+ IndexInfo::DEFAULTS[:store].should == false
74
+ IndexInfo::DEFAULTS[:type].should == String
75
+ end
76
+ end