public
Description: Library for accessing ThruDB documents.
Clone URL: git://github.com/technoweenie/activedocument.git
basic index doc_message stuff
technoweenie (author)
Sat Jan 12 03:39:00 -0800 2008
commit  f61a498cead3ecf65ed0b7dae1d8c771d187d12c
tree    a0930c90e61d5a1dbecebd7d68e4c5ff9919aefa
parent  78039500e9d7bf8214904cca4c3ff3939b2c9209
...
7
8
9
10
 
 
11
12
13
...
7
8
9
 
10
11
12
13
14
0
@@ -7,7 +7,8 @@ module ActiveDocument
0
     # class Foo
0
     # indexes :name => {:sortable => true}, :tags => nil
0
     def indexes(*args)
0
- @indexed_fields = args.first
0
+ @indexed_fields = args.last.is_a?(Hash) ? args.pop : {}
0
+ args.each { |a| @indexed_fields[a] ||= {} }
0
       @indexed_fields.keys.each do |key|
0
         @indexed_fields[key] ||= {}
0
       end
...
10
11
12
 
 
13
14
15
16
 
17
18
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
21
22
23
...
10
11
12
13
14
15
16
17
 
18
19
20
 
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
0
@@ -10,13 +10,28 @@ module ActiveDocument
0
     
0
     def save
0
       @id = manager.store self
0
+ index!
0
+ true
0
     end
0
     
0
     def index!
0
-
0
+ manager.index self
0
     end
0
     
0
- def index_doc_message
0
+ def doc_message
0
+ return nil if self.class.indexed_fields.nil? || self.class.indexed_fields.empty?
0
+ doc = DocMsg.new
0
+ doc.docid = id
0
+ doc.domain = 'whatever-domain'
0
+ doc.index = self.class.index_name
0
+ doc.fields = []
0
+ self.class.indexed_fields.each do |field, options|
0
+ f = Field.new
0
+ f.name = field.to_s
0
+ f.value = instance_variable_get("@#{field}")
0
+ doc.fields << f
0
+ end
0
+ doc
0
     end
0
   end
0
 end
0
\ No newline at end of file
...
53
54
55
 
56
57
58
59
...
53
54
55
56
57
58
59
60
0
@@ -53,6 +53,7 @@ module ActiveDocument
0
     end
0
     
0
     def index(record)
0
+ thrucene.add record.doc_message
0
     end
0
   end
0
 end
0
\ No newline at end of file
...
26
27
28
 
 
 
 
 
29
30
31
...
26
27
28
29
30
31
32
33
34
35
36
0
@@ -26,5 +26,10 @@ describe ActiveDocument do
0
       MockRecord.indexes :name => nil
0
       MockRecord.indexed_fields.should == {:name => {}}
0
     end
0
+
0
+ it "accepts array of attributes without custom options" do
0
+ MockRecord.indexes :contents, :name => {:sortable => true}
0
+ MockRecord.indexed_fields.should == {:name => {:sortable => true}, :contents => {}}
0
+ end
0
   end
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.