0

将代码从 Lucene 3.6 转换为 Lucene 4.1 后奇怪的测试失败

public void testIndexPuid() throws Exception {

        addReleaseOne();
        RAMDirectory ramDir = new RAMDirectory();
        createIndex(ramDir);

        IndexReader ir = IndexReader.open(ramDir);
        Fields fields = MultiFields.getFields(ir);
        Terms terms = fields.terms("puid");
        TermsEnum termsEnum = terms.iterator(null);
        termsEnum.next();
        assertEquals("efd2ace2-b3b9-305f-8a53-9803595c0e38", termsEnum.term());
    }

返回:

Expected :efd2ace2-b3b9-305f-8a53-9803595c0e38 Actual :[65 66 64 32 61 63 65 32 2d 62 33 62 39 2d 33 30 35 66 2d 38 61 35 33 2d 39 38 30 33 35 39 35 63 30 65 33 38 ]

似乎将该字段添加为二进制字段而不是文本字段,但我检查并使用已弃用的字段添加该字段

新字段(“puid”,值,Field.Index.NOT_ANALYZED_NO_NORMS,新关键字分析器())

所以不应该像以前一样工作吗?

4

1 回答 1

0

Doh,我的错误缺少 utf8ToString(),行应该是:assertEquals("efd2ace2-b3b9-305f-8a53-9803595c0e38", termsEnum.term().utf8ToString()); ——保罗·泰勒 2 月 19 日 22:20

于 2013-02-25T10:26:31.640 回答