2 wty19 wty19 于 2014.07.23 15:58 提问

lucene4.9 中文分词例子 失败

代码是这样的

    Directory directory = new RAMDirectory();
CharArraySet c = new  CharArraySet(Version.LUCENE_4_9, 1, true);
        c.add("#");
        IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_4_9,new SmartChineseAnalyzer(Version.LUCENE_4_9,c));

        IndexWriter indexWriter = new IndexWriter(directory,conf);
        Document doc=new Document();
        doc.add(new StringField("keyword","青菜#土豆#牛肉" ,Field.Store.YES ));
        doc.add(new StringField("id","1aaa" ,Field.Store.YES));
        indexWriter.addDocument(doc);  
        indexWriter.close();
Term term = new Term("keyword", "土豆");   
        AtomicReader atomicReader = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(directory));
        IndexSearcher searcher = new IndexSearcher(atomicReader);
        TopDocs tdoc = searcher.search(new TermQuery(term), 10);
        System.out.println(tdoc.totalHits);
        for(ScoreDoc s : tdoc.scoreDocs){
            Document firstHit =  searcher.doc(s.doc);
           System.out.println(firstHit.getField("id").stringValue());
        }

但是搜!不!到!,只有 Term = "青菜#土豆#牛肉" 才能全部收到。那个SmartChineseAnalyzer 我看文档,传入c 是stop标签,难道我理解错了?求解

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!