如何搜索在Lucene.NET一个Field.Index.NOT_ANALYZED场? [英] How to search a Field.Index.NOT_ANALYZED field in Lucene.NET?

查看:568
本文介绍了如何搜索在Lucene.NET一个Field.Index.NOT_ANALYZED场?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Lucene.NET。我加入领域

  Field.Index.NOT_ANALYZED
 

在Lucene的文档。有它在文档中加入

一个默认场

  Field.Index.ANALYZED
 

我在搜索默认字段没有困难;但是当我搜索一个特定领域,然后Lucene的返回0文件。但是,如果我改变,

  Field.Index.NOT_ANALYZED
 

  Field.Index.ANALYZED
 

那么事情正常工作。我觉得有一些做分析。任何机构可以指导我如何搜索 Field.Index.NOT_ANALYZED 字段?

下面是我如何创建查询分析器:

  QueryParser的解析器=
    新的QueryParser(
        Version.LUCENE_30,
        内容,
        新StandardAnalyzer(Version.LUCENE_30));
 

解决方案

ANALYZED 只是意味着该值是通过分析仪通过建立索引之前,而 NOT_ANALYZED 表示该值将被索引原样。后者是指像Hello World的值将被索引刚才正是这样的字符串Hello World。然而,语法的QueryParser类解析空间作为一个术语,分离器,创建两个术语你好和世界。

如果你创建了一个变种Q =新TermQuery(新名词(领域的Hello World))不是调用<$您可以到外地匹配C $ C>变种Q = queryParser.Parse(现场,世界你好)。

I am new to Lucene.NET. I am adding fields as

Field.Index.NOT_ANALYZED

in a Lucene document. There is one default field which is added in document as

Field.Index.ANALYZED

I have no difficulty in searching the default field; but when I search on a specific field then Lucene returns 0 document. However if I change,

Field.Index.NOT_ANALYZED

to

Field.Index.ANALYZED

then things work properly. I think there is something to do with Analyzer. Can any body guide me on how to search a Field.Index.NOT_ANALYZED field?

Here is how I am creating the query parser:

QueryParser parser = 
    new QueryParser(
        Version.LUCENE_30, 
        "content", 
        new StandardAnalyzer(Version.LUCENE_30));

解决方案

ANALYZED just means that the value is passed through an Analyzer before being indexed, while NOT_ANALYZED means that the value will be indexed as-is. The later means that a value like "hello world" will be indexed as just exactly that, the string "hello world". However, the syntax for the QueryParser class parses spaces as a term-separator, creating two terms "hello" and "world".

You will be able to match the field if you created a var q = new TermQuery(new Term(field, "hello world")) instead of calling var q = queryParser.Parse(field, "hello world").

这篇关于如何搜索在Lucene.NET一个Field.Index.NOT_ANALYZED场?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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