A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© HM代景康 高级黑马   /  2013-9-29 20:02  /  1115 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

最近需要些一个可配置的索引构建程序,需要在运行时调用Lucene包的如下类及其成员:

  引用

  Nested Class Summary

  static class Field.Index

  Specifies whether and how a field should be indexed.

  static class Field.Store

  Specifies whether and how a field should be stored.

  static class Field.TermVector

  Specifies whether and how a field should have term vectors.

  lucene api中称之为Nested Class,意为嵌套类,而嵌套类内部的File.Index的成员又是静态成员。

  引用

  Field Summary

  static Field.Index ANALYZED

  Index the tokens produced by running the field's value through an Analyzer.

  static Field.Index ANALYZED_NO_NORMS

  Expert: Index the tokens produced by running the field's value through an Analyzer, and also separately disable the storing of norms.

  static Field.Index NO

  Do not index the field value.

  static Field.Index NO_NORMS

  Deprecated. This has been renamed to NOT_ANALYZED_NO_NORMS

  static Field.Index NOT_ANALYZED

  Index the field's value without using an Analyzer, so it can be searched.

  static Field.Index NOT_ANALYZED_NO_NORMS

  Expert: Index the field's value without an Analyzer, and also disable the storing of norms.

  static Field.Index TOKENIZED

  Deprecated. this has been renamed to ANALYZED

  static Field.Index UN_TOKENIZED

  Deprecated. This has been renamed to NOT_ANALYZED

  一个棘手的问题,如果获得这些内部静态成员?

  最后采用了如下方法:

  //运行时调用Filed.Index类型

  Java代码

  Class<?> cls = org.apache.lucene.document.Field.Index.class;

  java.lang.reflect.Field indexDeclareField = cls.getDeclaredField(field.getIndex());

  Object indexDeclareFieldType = indexDeclareField.get(cls);

  org.apache.lucene.document.Field.Index filedIndex = (org.apache.lucene.document.Field.Index)indexDeclareFieldType;

  //运行时调用Field.Store类型

  Class<?> clsStore = org.apache.lucene.document.Field.Index.class;

  java.lang.reflect.Field storeDeclareField = cls.getDeclaredField(field.getIndex());

  Object indexStoreDeclareField = indexDeclareField.get(cls);

  org.apache.lucene.document.Field.Store filedStore = (org.apache.lucene.document.Field.Store)indexStoreDeclareField;

评分

参与人数 1技术分 +1 收起 理由
乔兵 + 1

查看全部评分

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马