Namazu-devel-ja(旧)


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

namadu patch for rbnamazu-0.2



大島です。

namadu-0.0 を rbnamazu-0.2 に対応させる応急パッチを作成しましたので、
添付しておきます。namadu.rb のみを書き換えます。

rbnamazu 自身の複数インデックス対応の方は、ドキュメント生成部分
(Namazu::Document)の実装をかなり根本的にやり直す必要があるので、ちょっ
と時間がかかると思います。
--- namadu-0.0/namadu.rb	Mon Jun 26 04:27:59 2000
+++ namadu-0.0/nmznmd.rb	Sun Jun 25 17:37:33 2000
@@ -8,8 +8,8 @@
 
 require 'rbnamazu'
 
-class Namadu
-  class NamazuFieldLoader < NamazuFieldAll
+class Namazu
+  class FieldAll
     def gets_as_array(docid, fieldnames = nil)
       unless fieldnames
 	fieldnames = @fieldnames
@@ -27,7 +27,9 @@
       v.chomp
     end
   end
+end
 
+class Namadu
   class Doc
     def initialize(index, docid, score, time)
       @index = index
@@ -68,14 +70,12 @@
   end
 
   class Result
-    def initialize(list, words)
+    def initialize(list, query)
       @ref_hits = Hash.new(0)
       @docs = []
       list.each do |idx|
-	r = idx.find(words)
-	r.ref_hits.each do |k,v|
-	  @ref_hits[k] += v
-	end
+	r = idx.find(query)
+	@ref_hits[idx.index()] = r.ref_hits()
 	@docs.concat(r.docs)
       end
       @num_docs = @docs.size
@@ -129,37 +129,28 @@
 
   class Index
     class Result1
-      def initialize(index, words)
-	scores, times, ref = index.finder.get_scores(words)
+      def initialize(index, query)
+	result = index.finder().search(query)
 
-	@ref_hits = make_ref_hits(words, ref)
+	@ref_hits = result.to_s()
 	@docs = []
-	scores.each do |k, v|
-	  @docs.push(Doc.new(index, k, v, times[k]))
+	result.docids().each do |docid|
+	  @docs.push(Doc.new(index, docid, result.score(docid), result.time(docid)))
 	end
 	@num_docs = @docs.size
       end
       attr_reader(:ref_hits, :num_docs, :docs)
-      
-      private
-      def make_ref_hits(words, counts)
-	hash = {}
-	words.each_with_index do |w, i|
-	  hash[w] = counts[i]	
-	end
-	hash.freeze
-      end
     end
 
     def initialize(index)
       @index = index.dup.freeze
-      @finder = NamazuScores.new(@index)
-      @fields_loader = NamazuFieldLoader.new(@index)
+      @finder = Namazu::Index.new(@index)
+      @fields_loader = @finder.nmzfieldall()
     end
-    attr_reader(:finder, :fields_loader)
+    attr_reader(:index, :finder, :fields_loader)
 
-    def find(words)
-      Result1.new(self, words)
+    def find(query)
+      Result1.new(self, query)
     end
   end
 
@@ -168,17 +159,17 @@
   end
 
   public
-  def search(words, order='score')
-    words = words.collect { |w| w.downcase }      
-    r = Result.new(@list, words)
+  def search(query, order='score')
+    query = query.to_s() if query.kind_of?(Array)
+    r = Result.new(@list, query)
     r.sort!(order) if order
     yield(r) if iterator? 		# GC trick
     r
   end
 
   public
-  def query(words, order='score', fields=nil, max=20, whence=0)
-    r = search(words, order)
+  def query(query, order='score', fields=nil, max=20, whence=0)
+    r = search(query, order)
     list = r.result(fields, max, whence)
     [list, r.num_docs, r.ref_hits]
   end
@@ -206,9 +197,10 @@
       DRb.thread.join
     end
   else
-    words = ARGV.shift.split
+    query = ARGV.shift
     nmd = Namadu.new(ARGV)
-    r = nmd.search(words, 'field:subject')
+    r = nmd.search(query, 'field:subject')
     r.result(%w(subject uri score)) do |rec| p rec end
+    p r.ref_hits
   end
 end