IndexReader.terms()オプションのフィールド()オブジェクトを受け付けます。 フィールドオブジェクトは、2つの引数、フィールド名、および "用語フィールド"と "用語テキスト"を呼び出す値から構成されます。
'term text'に空の値を指定してField引数を指定することで、関連する用語で用語の繰り返しを開始できます。 PyLuceneにファセットを実行する方法を探して
lindex = SimpleFSDirectory(File(indexdir))
ireader = IndexReader.open(lindex, True)
# Query the lucene index for the terms starting at a term named "field_name"
terms = ireader.terms(Term("field_name", "")) #Start at the field "field_name"
facets = {'other': 0}
while terms.next():
if terms.term().field() != "field_name": #We've got every value
break
print "Field Name:", terms.term().field()
print "Field Value:", terms.term().text()
print "Matching Docs:", int(ireader.docFreq(term))
うまくいけば、他の人は、この記事に出くわし表示されます。キーは、そのまま用語を索引付けすることです。完全性のために、これはフィールド値をどのように索引付けするかです。
dir = SimpleFSDirectory(File(indexdir))
analyzer = StandardAnalyzer(Version.LUCENE_30)
writer = IndexWriter(dir, analyzer, True, IndexWriter.MaxFieldLength(512))
print "Currently there are %d documents in the index..." % writer.numDocs()
print "Adding %s Documents to Index..." % docs.count()
for val in terms:
doc = Document()
#Store the field, as-is, with term-vectors.
doc.add(Field("field_name", val, Field.Store.YES, Field.Index.NOT_ANALYZED, Field.TermVector.YES))
writer.addDocument(doc)
writer.optimize()
writer.close()
私はこれが解決策になるかもしれないと思う... http://wiki.apache.org/lucene-java/LuceneFAQ#How_do_I_retrieve_all_the_values_of_a_particular_field_that_exists_within_an_index.2C_across_all_documents.3F –