这次的笔记是记录lucene中的Filed字段常见的几种方法,如下
new StringField("String", "hello world", Store.YES);// 创建索引但不分词
new LongField("Long", 1L, Store.YES);// 分词创建索引
new IntField("int", 1, Store.YES);// 分词创建索引
new DoubleField("Double", 3.0D, Store.YES);// 分词创建索引
new FloatField("Float", 1.0F, Store.YES);// 分词创建索引
new StoredField("Stored", "stored1,stored2,stored3");// 不创建分词索引,默认保存,实际没值
还可以这样子写
FieldType ft = new FieldType();//下面三个设置中必有一个是true(如果setTokenized = true,setIndexed和setStored必有一个是true,不然也没意义), 不然会报错,如下面红色的代码,因为没意义
ft.setIndexed(true);// 要建索引
ft.setStored(true);// 要保存
ft.setTokenized(true);// 要分词
Field fd = new Field("diy", "jack,rose", ft);
Exception in thread "main" java.lang.IllegalArgumentException: it doesn't make sense to have a field that is neither indexed nor stored
OK,就记录这么多先。