Closed barrycheng closed 7 years ago
Analyzer analyzer = new HanLPIndexAnalyzer();////////////////////////////////////////////////////
IndexWriterConfig config = new IndexWriterConfig(analyzer);
config.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
Directory directory = new RAMDirectory();
IndexWriter indexWriter = new IndexWriter(directory, config);
Document document = new Document();
document.add(new TextField("content", "[新闻]服务大众。", Field.Store.YES));
indexWriter.addDocument(document);
document = new Document();
document.add(new TextField("content", "[经济学]商品和服务", Field.Store.YES));
indexWriter.addDocument(document);
document = new Document();
document.add(new TextField("content", "[服装店]老人头男皮带", Field.Store.YES));
indexWriter.addDocument(document);
indexWriter.commit();
indexWriter.close();
IndexReader ireader = DirectoryReader.open(directory);
IndexSearcher isearcher = new IndexSearcher(ireader);
QueryParser parser = new QueryParser("content", new HanLPAnalyzer());
Query query = parser.parse("老人头");
ScoreDoc[] hits = isearcher.search(query, 300000).scoreDocs;
assertEquals(1, hits.length);
for (ScoreDoc scoreDoc : hits)
{
Document targetDoc = isearcher.doc(scoreDoc.doc);
System.out.println(targetDoc.getField("content").stringValue());
}
[服装店]老人头男皮带
版本: Solr 6.2
Schema.xml:
Analyse:![default](https://cloud.githubusercontent.com/assets/8085838/19323542/fbd90684-90ef-11e6-8de6-37f46d8ce578.png)
问题: 索引中 老人头男皮带(505J014L)包邮 被分为 老人头 | 老人 | 人头 ,而我输入的老人头 被分为 老 | 人头,导致搜索不到结果,请问这样的原因是什么?如何处理?