开发者

trouble with TermFreqVector in lucene.net

i've been trying to get the frequency of terms of a document usin TermFreqVvector, here is my code,

LuceneStore.Directory dir = LuceneStore.FSDirectory.GetDirectory("e:/indexDir", true);

    IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(), true);
    Document doc = new Document();
    doc.Add(new Field("Content", "This is a beautiful house", Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.YES));
    writer.AddDocument(doc);
    writer.Optimize();
    writer.Close();

    IndexReader reader = IndexReader.Open(dir);
    TermFreqVector termFreq = reader.GetTermFreqVector(0, "content");
    string[] term = termFreq.GetTerms();

but i get the error msg "Object reference not set to an instance of 开发者_StackOverflow社区an object" on the line string[] term = termFreq.GetTerms();

can anyone help!!!!!


The GetTermFreqVector method is documented to return null if the storeTermVector flag hasn't been set - are you sure it's set in your case?

EDIT: I've just noticed that you're using "Content" as the field name in the constructor, and then "content" when you're asking for the term frequency vector. That could easily be the problem if field names are case-sensitive. I suggest you create a constant string used everywhere you want to refer to the field, for consistency.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜