6115 |
04 Feb 21 |
nicklas |
1 |
package net.sf.basedb.varsearch.fields; |
6115 |
04 Feb 21 |
nicklas |
2 |
|
6115 |
04 Feb 21 |
nicklas |
3 |
import java.util.Collection; |
6115 |
04 Feb 21 |
nicklas |
4 |
|
6115 |
04 Feb 21 |
nicklas |
5 |
import org.apache.lucene.document.Field; |
6115 |
04 Feb 21 |
nicklas |
6 |
import org.apache.lucene.document.FieldType; |
6115 |
04 Feb 21 |
nicklas |
7 |
import org.apache.lucene.index.IndexOptions; |
6115 |
04 Feb 21 |
nicklas |
8 |
|
6115 |
04 Feb 21 |
nicklas |
9 |
import net.sf.basedb.util.Values; |
6115 |
04 Feb 21 |
nicklas |
10 |
|
6115 |
04 Feb 21 |
nicklas |
11 |
/** |
6115 |
04 Feb 21 |
nicklas |
Field that stores a comma-separated list of values. This is basically |
6115 |
04 Feb 21 |
nicklas |
a StringField with tokenization and normalization enabled. |
6115 |
04 Feb 21 |
nicklas |
14 |
|
6115 |
04 Feb 21 |
nicklas |
To enable searching on individual values, the Analyzer implementation |
6115 |
04 Feb 21 |
nicklas |
must at least split on comma and white-space. |
6115 |
04 Feb 21 |
nicklas |
17 |
|
6115 |
04 Feb 21 |
nicklas |
@author nicklas |
6115 |
04 Feb 21 |
nicklas |
19 |
*/ |
6115 |
04 Feb 21 |
nicklas |
20 |
public class ListField |
6115 |
04 Feb 21 |
nicklas |
21 |
extends Field |
6115 |
04 Feb 21 |
nicklas |
22 |
{ |
6115 |
04 Feb 21 |
nicklas |
23 |
|
6115 |
04 Feb 21 |
nicklas |
24 |
public static final FieldType TYPE_STORED = new FieldType(); |
6115 |
04 Feb 21 |
nicklas |
25 |
public static final FieldType TYPE_NOT_STORED = new FieldType(); |
6115 |
04 Feb 21 |
nicklas |
26 |
|
6115 |
04 Feb 21 |
nicklas |
27 |
static |
6115 |
04 Feb 21 |
nicklas |
28 |
{ |
6115 |
04 Feb 21 |
nicklas |
29 |
TYPE_STORED.setIndexOptions(IndexOptions.DOCS); |
6115 |
04 Feb 21 |
nicklas |
30 |
TYPE_STORED.setStored(true); |
6115 |
04 Feb 21 |
nicklas |
31 |
TYPE_STORED.setTokenized(true); |
6115 |
04 Feb 21 |
nicklas |
32 |
TYPE_STORED.freeze(); |
6115 |
04 Feb 21 |
nicklas |
33 |
|
6115 |
04 Feb 21 |
nicklas |
34 |
TYPE_NOT_STORED.setIndexOptions(IndexOptions.DOCS); |
6115 |
04 Feb 21 |
nicklas |
35 |
TYPE_NOT_STORED.setStored(false); |
6115 |
04 Feb 21 |
nicklas |
36 |
TYPE_NOT_STORED.setTokenized(true); |
6115 |
04 Feb 21 |
nicklas |
37 |
TYPE_NOT_STORED.freeze(); |
6115 |
04 Feb 21 |
nicklas |
38 |
} |
6115 |
04 Feb 21 |
nicklas |
39 |
|
6115 |
04 Feb 21 |
nicklas |
40 |
/** |
6115 |
04 Feb 21 |
nicklas |
Create a list field from a collection of values. The values will |
6115 |
04 Feb 21 |
nicklas |
be indexed and optionally stored as a single string with |
6115 |
04 Feb 21 |
nicklas |
comma-separated values. |
6115 |
04 Feb 21 |
nicklas |
44 |
*/ |
6115 |
04 Feb 21 |
nicklas |
45 |
public ListField(String name, Collection<String> values, Field.Store stored) |
6115 |
04 Feb 21 |
nicklas |
46 |
{ |
6121 |
08 Feb 21 |
nicklas |
47 |
super(name, Values.getString(values, ", ", true), stored == Field.Store.YES ? TYPE_STORED : TYPE_NOT_STORED); |
6115 |
04 Feb 21 |
nicklas |
48 |
} |
6115 |
04 Feb 21 |
nicklas |
49 |
} |