使用Lucene.NET在单令牌字段中搜索 [英] Search in Single-Token-Field using Lucene.NET

查看:95
本文介绍了使用Lucene.NET在单令牌字段中搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Lucene.NET 3.0.3来索引word-,excel-等文档的内容以及每个文档的一些自定义字段.
如果我将名为"title" 的字段索引为 Field.Index.NOT_ANALYZED ,则Lucene-Index会以正确的形式存储该字段.孔标题存储在单个令牌中.那就是我想要的.

I´m using Lucene.NET 3.0.3 for indexing the content of word-, excel-, etc. documents and some custom fields for each document.
If I index a field named "title" as Field.Index.NOT_ANALYZED the Lucene-Index stored the field in correct form. The hole title is stored in a single token. That´s what I want.

例如文档标题为"Lorem ipsum dolor"
Lucene索引中的字段:"Lorem ipsum dolor"

如果我在该字段中使用精确搜索进行搜索,则不会得到任何结果.
我的搜索字词如下:标题:"Lorem ipsum dolor"
要搜索我,请使用相同的StandardAnalzer.

If I search using exact search in this field I get no results.
My searchterm looks like: title:"Lorem ipsum dolor"
For searching i´m use the same StandardAnalzer.

为什么找不到文档?

推荐答案

StandardAnalyzer除其他分隔符外,对空格敏感.也就是说,它将搜索词标记为三个标记:

StandardAnalyzer is sensitive to whitespace, among other delimiters. That is, it tokenizes the search term into three tokens:

( Lorem, ipsum, dolor )

但是您使用Field.Index.NOT_ANALYZED为字段title编制了索引,因此上述三个标记中的任何一个都不能与该字段中的单个标记匹配:

But you indexed field title using Field.Index.NOT_ANALYZED so none of the three tokens above can match the single token in this field:

( Lorem ipsum dolor )

使用KeywordAnalyzer,它将整个字段值标记为单个标记.与往常一样,您需要使用相同的分析器进行索引和搜索.

Use KeywordAnalyzer, which tokenizes the entire field value as a single token. As always, you need to use the same analyzer for both indexing and searching.

这篇关于使用Lucene.NET在单令牌字段中搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆