📄 field.java
字号:
this.isStored = true; this.isCompressed = true; } else if (store == Store.NO){ this.isStored = false; this.isCompressed = false; } else throw new IllegalArgumentException("unknown store parameter " + store); if (index == Index.NO) { this.isIndexed = false; this.isTokenized = false; } else if (index == Index.TOKENIZED) { this.isIndexed = true; this.isTokenized = true; } else if (index == Index.UN_TOKENIZED) { this.isIndexed = true; this.isTokenized = false; } else if (index == Index.NO_NORMS) { this.isIndexed = true; this.isTokenized = false; this.omitNorms = true; } else { throw new IllegalArgumentException("unknown index parameter " + index); } this.isBinary = false; setStoreTermVector(termVector); } /** * Create a tokenized and indexed field that is not stored. Term vectors will * not be stored. * * @param name The name of the field * @param reader The reader with the content * @throws NullPointerException if name or reader is <code>null</code> */ public Field(String name, Reader reader) { this(name, reader, TermVector.NO); } /** * Create a tokenized and indexed field that is not stored, optionally with * storing term vectors. * * @param name The name of the field * @param reader The reader with the content * @param termVector Whether term vector should be stored * @throws NullPointerException if name or reader is <code>null</code> */ public Field(String name, Reader reader, TermVector termVector) { if (name == null) throw new NullPointerException("name cannot be null"); if (reader == null) throw new NullPointerException("reader cannot be null"); this.name = name.intern(); // field names are interned this.fieldsData = reader; this.isStored = false; this.isCompressed = false; this.isIndexed = true; this.isTokenized = true; this.isBinary = false; setStoreTermVector(termVector); } /** * Create a stored field with binary value. Optionally the value may be compressed. * * @param name The name of the field * @param value The binary value * @param store How <code>value</code> should be stored (compressed or not) * @throws IllegalArgumentException if store is <code>Store.NO</code> */ public Field(String name, byte[] value, Store store) { if (name == null) throw new IllegalArgumentException("name cannot be null"); if (value == null) throw new IllegalArgumentException("value cannot be null"); this.name = name.intern(); this.fieldsData = value; if (store == Store.YES){ this.isStored = true; this.isCompressed = false; } else if (store == Store.COMPRESS) { this.isStored = true; this.isCompressed = true; } else if (store == Store.NO) throw new IllegalArgumentException("binary values can't be unstored"); else throw new IllegalArgumentException("unknown store parameter " + store); this.isIndexed = false; this.isTokenized = false; this.isBinary = true; setStoreTermVector(TermVector.NO); } private void setStoreTermVector(TermVector termVector) { if (termVector == TermVector.NO) { this.storeTermVector = false; this.storePositionWithTermVector = false; this.storeOffsetWithTermVector = false; } else if (termVector == TermVector.YES) { this.storeTermVector = true; this.storePositionWithTermVector = false; this.storeOffsetWithTermVector = false; } else if (termVector == TermVector.WITH_POSITIONS) { this.storeTermVector = true; this.storePositionWithTermVector = true; this.storeOffsetWithTermVector = false; } else if (termVector == TermVector.WITH_OFFSETS) { this.storeTermVector = true; this.storePositionWithTermVector = false; this.storeOffsetWithTermVector = true; } else if (termVector == TermVector.WITH_POSITIONS_OFFSETS) { this.storeTermVector = true; this.storePositionWithTermVector = true; this.storeOffsetWithTermVector = true; } else { throw new IllegalArgumentException("unknown termVector parameter " + termVector); } } /** True iff the value of the field is to be stored in the index for return with search hits. It is an error for this to be true if a field is Reader-valued. */ public final boolean isStored() { return isStored; } /** True iff the value of the field is to be indexed, so that it may be searched on. */ public final boolean isIndexed() { return isIndexed; } /** True iff the value of the field should be tokenized as text prior to indexing. Un-tokenized fields are indexed as a single word and may not be Reader-valued. */ public final boolean isTokenized() { return isTokenized; } /** True if the value of the field is stored and compressed within the index */ public final boolean isCompressed() { return isCompressed; } /** True iff the term or terms used to index this field are stored as a term * vector, available from {@link IndexReader#getTermFreqVector(int,String)}. * These methods do not provide access to the original content of the field, * only to terms used to index it. If the original content must be * preserved, use the <code>stored</code> attribute instead. * * @see IndexReader#getTermFreqVector(int, String) */ public final boolean isTermVectorStored() { return storeTermVector; } /** * True iff terms are stored as term vector together with their offsets * (start and end positon in source text). */ public boolean isStoreOffsetWithTermVector(){ return storeOffsetWithTermVector; } /** * True iff terms are stored as term vector together with their token positions. */ public boolean isStorePositionWithTermVector(){ return storePositionWithTermVector; } /** True iff the value of the filed is stored as binary */ public final boolean isBinary() { return isBinary; } /** True if norms are omitted for this indexed field */ public boolean getOmitNorms() { return omitNorms; } /** Expert: * * If set, omit normalization factors associated with this indexed field. * This effectively disables indexing boosts and length normalization for this field. */ public void setOmitNorms(boolean omitNorms) { this.omitNorms=omitNorms; } /** Prints a Field for human consumption. */ public final String toString() { StringBuffer result = new StringBuffer(); if (isStored) { result.append("stored"); if (isCompressed) result.append("/compressed"); else result.append("/uncompressed"); } if (isIndexed) { if (result.length() > 0) result.append(","); result.append("indexed"); } if (isTokenized) { if (result.length() > 0) result.append(","); result.append("tokenized"); } if (storeTermVector) { if (result.length() > 0) result.append(","); result.append("termVector"); } if (storeOffsetWithTermVector) { if (result.length() > 0) result.append(","); result.append("termVectorOffsets"); } if (storePositionWithTermVector) { if (result.length() > 0) result.append(","); result.append("termVectorPosition"); } if (isBinary) { if (result.length() > 0) result.append(","); result.append("binary"); } if (omitNorms) { result.append(",omitNorms"); } result.append('<'); result.append(name); result.append(':'); if (fieldsData != null) { result.append(fieldsData); } result.append('>'); return result.toString(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -