を使った Solr インデックスからの単語の抽出


#! /usr/local/jython2.5.1/jython
# -*- coding: utf-8 -*-

from org.apache.lucene.store import FSDirectory
from org.apache.lucene.index import IndexReader
from org.apache.lucene.index import Term
from org.apache.lucene.index import TermEnum

if __name__ == "__main__":

 # インデックスのオープン
 indexPath = "Solrのインデックスのディレクトリ hoge/index/"
 dir = FSDirectory.getDirectory(indexPath, False)
 reader = IndexReader.open( dir );

 # タームの取得
 Term = Term( "タームを取得するフィールド名", "" );
 termEnum = reader.terms( Term );

 while termEnum.next():
  term = termEnum.term()
  print term.field(), term.text(), reader.docFreq( term )