|
| 1 | +/* |
| 2 | + * This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 |
| 3 | + * United States License. To view a copy of this license, visit |
| 4 | + * http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to |
| 5 | + * Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. |
| 6 | + * |
| 7 | + * Copyright (c) 2012, https://stackoverflow.com/users/1270457/amas |
| 8 | + * Copyright (c) 2012, https://stackoverflow.com/questions/11945728/how-to-use-termvector-lucene-4-0 |
| 9 | + * Portions Copyright (c) 2018, Chris Fraire <cfraire@me.com>. |
| 10 | + */ |
| 11 | + |
| 12 | +package org.opensolaris.opengrok.analysis; |
| 13 | + |
| 14 | +import java.io.Reader; |
| 15 | +import org.apache.lucene.analysis.TokenStream; |
| 16 | +import org.apache.lucene.document.Field; |
| 17 | +import org.apache.lucene.document.FieldType; |
| 18 | +import org.apache.lucene.index.IndexOptions; |
| 19 | + |
| 20 | +/** |
| 21 | + * Represents an OpenGrok-customized tokenized, text field with stored term |
| 22 | + * vectors to centralize settings across all the analyzers. |
| 23 | + */ |
| 24 | +public class OGKTextVecField extends Field { |
| 25 | + |
| 26 | + /** Indexed, tokenized, not stored. */ |
| 27 | + public static final FieldType TYPE_NOT_STORED = new FieldType(); |
| 28 | + |
| 29 | + /** Indexed, tokenized, stored. */ |
| 30 | + public static final FieldType TYPE_STORED = new FieldType(); |
| 31 | + |
| 32 | + static { |
| 33 | + TYPE_NOT_STORED.setIndexOptions( |
| 34 | + IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS); |
| 35 | + TYPE_NOT_STORED.setTokenized(true); |
| 36 | + TYPE_NOT_STORED.setStoreTermVectors(true); |
| 37 | + TYPE_NOT_STORED.freeze(); |
| 38 | + |
| 39 | + TYPE_STORED.setIndexOptions( |
| 40 | + IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS); |
| 41 | + TYPE_STORED.setTokenized(true); |
| 42 | + TYPE_STORED.setStoreTermVectors(true); |
| 43 | + TYPE_STORED.setStored(true); |
| 44 | + TYPE_STORED.freeze(); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Creates a new un-stored instance with Reader value. |
| 49 | + * @param name |
| 50 | + * @param reader |
| 51 | + */ |
| 52 | + public OGKTextVecField(String name, Reader reader) { |
| 53 | + super(name, reader, TYPE_NOT_STORED); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * Creates a new instance with {@link Reader} value. |
| 58 | + * @param name |
| 59 | + * @param reader |
| 60 | + * @param store |
| 61 | + */ |
| 62 | + public OGKTextVecField(String name, Reader reader, Store store) { |
| 63 | + super(name, reader, store == Store.YES ? TYPE_STORED : TYPE_NOT_STORED); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Creates a new instance with {@code String} value. |
| 68 | + * @param name |
| 69 | + * @param value |
| 70 | + * @param store |
| 71 | + */ |
| 72 | + public OGKTextVecField(String name, String value, Store store) { |
| 73 | + super(name, value, store == Store.YES ? TYPE_STORED : TYPE_NOT_STORED); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Creates a new un-stored instance with {@link TokenStream} value. |
| 78 | + * @param name |
| 79 | + * @param stream |
| 80 | + */ |
| 81 | + public OGKTextVecField(String name, TokenStream stream) { |
| 82 | + super(name, stream, TYPE_NOT_STORED); |
| 83 | + } |
| 84 | +} |
0 commit comments