如何在 lucene 4.0 中控制索引字段 [英] How to control Indexing a field in lucene 4.0

查看:27
本文介绍了如何在 lucene 4.0 中控制索引字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Lucene 3.9 版本之前,我们可以使用 FIELD.INDEX.NO 或 FIELD.INDEX.ANALYZED 等指定索引或不索引字段.但是在 lucene 4.0 中没有可用的构造函数,我们可以在其中定义这个.在这个版本中我们如何控制索引?

Until Lucene version 3.9 , we could specify to index or not to index a field by using FIELD.INDEX.NO or FIELD.INDEX.ANALYZED etc. But in lucene 4.0 there is no constructor available, in which we may define this . How do we control indexing in this version?

我的意思是,如果我想将字段名称"存储在索引中但不想对其进行索引,那么我该如何在 lucene 4.0 中做到这一点?

I mean if i want a field "name" to be stored in index but doesn't want to index it, then how can i do it in lucene 4.0?

推荐答案

采用 Field.Index 参数的构造函数可用,但在 4.0 中已弃用,不应使用.相反,您应该查看 Field 的子类来控制字段的索引方式.

Constructors taking Field.Index arguments are available, but are deprecated in 4.0, and should not be used. Instead, you should look to subclasses of Field to control how a field is indexed.

  • StringField 是标准的未分析索引字段.被索引的字段是单个标记.它是合适的东西,比如标识符,您只需要搜索完全匹配的东西.

  • StringField is the standard un-analyzed indexed field. The field is indexed is a single token. It is appropriate things like identifiers, for which you only need to search for exact matches.

TextField 是文本内容的标准分析(当然还有索引)字段.它是全文搜索的合适选择.

TextField is the standard analyzed (and, of course, indexed) field, for textual content. It is an appropriate choice for full-text searching.

StoredField 是一个完全没有索引的存储字段(因此,不可搜索).

StoredField is a stored field that is not indexed at all (and so, is not searchable).

除了 StoredField,每个都可以传递一个 Field.Store 值作为构造函数参数,类似于 Lucene 3.6.

Except StoredField, each of these can be passed a Field.Store value as a constructor argument, similar to Lucene 3.6.

有关此更改的更多信息,请查看 Lucene 迁移指南,尤其是标题为:将 IndexableFieldType 与字段实例分开"的部分

For more information on this change, take a look at the Lucene Migration Guide, particularly the sections titled: "Separate IndexableFieldType from Field instances"

这篇关于如何在 lucene 4.0 中控制索引字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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