Sha256: 129d1b85172406abf3ae6ac54ff2c1340b924ed47fda7bed17496a440e295d78
Contents?: true
Size: 1.13 KB
Versions: 1
Compression:
Stored size: 1.13 KB
Contents
# make lucene/solr a bit more rubyis module Solrium include_class 'org.apache.lucene.index.TermEnum' include_class 'org.apache.lucene.index.Term' include_class 'org.apache.lucene.document.Document' include_class 'org.apache.lucene.document.Field' class Document def [](n) self.getField(n) end def inspect "Document: " + to_hash.inspect end def to_hash fields.inject({}) do |h, f| h[f.name] = f.stringValue() h end end end class Field def inspect "#{name}: #{to_s}" end def to_s self.stringValue() end end # lets you use Term['foo'] ==> Term.new('default', foo) class Term def self.[](t) new('default', t) end end #make TermEnum a bit friendlier to use class TermEnum include Enumerable def each while self.next() yield(self.term()) end end def to_java_array elements = to_a array = java.lang.reflect.Array.newInstance(Term.java_class, elements.length) elements.each_with_index { |e,i| array[i] = e } array end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jberkel-solrium-0.1.0 | lib/solr_ext.rb |