Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
Fieldable.cs
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 using System;
19 using System.IO;
20 using TokenStream = Lucene.Net.Analysis.TokenStream;
21 using FieldInvertState = Lucene.Net.Index.FieldInvertState;
22 
23 namespace Lucene.Net.Documents
24 {
25  /// <summary> Synonymous with <see cref="Field" />.
26  ///
27  /// <p/><bold>WARNING</bold>: This interface may change within minor versions, despite Lucene's backward compatibility requirements.
28  /// This means new methods may be added from version to version. This change only affects the Fieldable API; other backwards
29  /// compatibility promises remain intact. For example, Lucene can still
30  /// read and write indices created within the same major version.
31  /// <p/>
32  ///
33  ///
34  /// </summary>
35  public interface IFieldable
36  {
37  /// <summary>Gets or sets the boost factor for hits for this field. This value will be
38  /// multiplied into the score of all hits on this this field of this
39  /// document.
40  ///
41  /// <p/>The boost is multiplied by <see cref="Lucene.Net.Documents.Document.Boost" /> of the document
42  /// containing this field. If a document has multiple fields with the same
43  /// name, all such values are multiplied together. This product is then
44  /// used to compute the norm factor for the field. By
45  /// default, in the <see cref="Lucene.Net.Search.Similarity.ComputeNorm(String,Lucene.Net.Index.FieldInvertState)"/>
46  /// method, the boost value is multiplied
47  /// by the <see cref="Lucene.Net.Search.Similarity.LengthNorm(String,int)"/>
48  /// and then rounded by <see cref="Lucene.Net.Search.Similarity.EncodeNorm(float)" /> before it is stored in the
49  /// index. One should attempt to ensure that this product does not overflow
50  /// the range of that encoding.
51  ///
52  /// <p/>The default value is 1.0.
53  ///
54  /// <p/>Note: this value is not stored directly with the document in the index.
55  /// Documents returned from <see cref="Lucene.Net.Index.IndexReader.Document(int)" /> and
56  /// <see cref="Lucene.Net.Search.Searcher.Doc(int)" /> may thus not have the same value present as when
57  /// this field was indexed.
58  ///
59  /// </summary>
60  /// <seealso cref="Lucene.Net.Documents.Document.Boost">
61  /// </seealso>
62  /// <seealso cref="Lucene.Net.Search.Similarity.ComputeNorm(String, FieldInvertState)">
63  /// </seealso>
64  /// <seealso cref="Lucene.Net.Search.Similarity.EncodeNorm(float)">
65  /// </seealso>
66  float Boost { get; set; }
67 
68  /// <summary>Returns the name of the field as an interned string.
69  /// For example "date", "title", "body", ...
70  /// </summary>
71  string Name { get; }
72 
73  /// <summary>The value of the field as a String, or null.
74  /// <p/>
75  /// For indexing, if isStored()==true, the stringValue() will be used as the stored field value
76  /// unless isBinary()==true, in which case GetBinaryValue() will be used.
77  ///
78  /// If isIndexed()==true and isTokenized()==false, this String value will be indexed as a single token.
79  /// If isIndexed()==true and isTokenized()==true, then tokenStreamValue() will be used to generate indexed tokens if not null,
80  /// else readerValue() will be used to generate indexed tokens if not null, else stringValue() will be used to generate tokens.
81  /// </summary>
82  string StringValue { get; }
83 
84  /// <summary>The value of the field as a Reader, which can be used at index time to generate indexed tokens.</summary>
85  /// <seealso cref="StringValue()">
86  /// </seealso>
87  TextReader ReaderValue { get; }
88 
89  /// <summary>The TokenStream for this field to be used when indexing, or null.</summary>
90  /// <seealso cref="StringValue()">
91  /// </seealso>
92  TokenStream TokenStreamValue { get; }
93 
94  /// <summary>True if the value of the field is to be stored in the index for return
95  /// with search hits.
96  /// </summary>
97  bool IsStored { get; }
98 
99  /// <summary>True if the value of the field is to be indexed, so that it may be
100  /// searched on.
101  /// </summary>
102  bool IsIndexed { get; }
103 
104  /// <summary>True if the value of the field should be tokenized as text prior to
105  /// indexing. Un-tokenized fields are indexed as a single word and may not be
106  /// Reader-valued.
107  /// </summary>
108  bool IsTokenized { get; }
109 
110  /// <summary>True if the term or terms used to index this field are stored as a term
111  /// vector, available from <see cref="Lucene.Net.Index.IndexReader.GetTermFreqVector(int,String)" />.
112  /// These methods do not provide access to the original content of the field,
113  /// only to terms used to index it. If the original content must be
114  /// preserved, use the <c>stored</c> attribute instead.
115  ///
116  /// </summary>
117  /// <seealso cref="Lucene.Net.Index.IndexReader.GetTermFreqVector(int, String)">
118  /// </seealso>
119  bool IsTermVectorStored { get; }
120 
121  /// <summary> True if terms are stored as term vector together with their offsets
122  /// (start and end positon in source text).
123  /// </summary>
124  bool IsStoreOffsetWithTermVector { get; }
125 
126  /// <summary> True if terms are stored as term vector together with their token positions.</summary>
127  bool IsStorePositionWithTermVector { get; }
128 
129  /// <summary>True if the value of the field is stored as binary </summary>
130  bool IsBinary { get; }
131 
132  /// <summary>
133  /// True if norms are omitted for this indexed field.
134  /// <para>
135  /// Expert:
136  /// If set, omit normalization factors associated with this indexed field.
137  /// This effectively disables indexing boosts and length normalization for this field.
138  /// </para>
139  /// </summary>
140  bool OmitNorms { get; set; }
141 
142 
143  /// <summary> Indicates whether a Field is Lazy or not. The semantics of Lazy loading are such that if a Field is lazily loaded, retrieving
144  /// it's values via <see cref="StringValue()" /> or <see cref="GetBinaryValue()" /> is only valid as long as the <see cref="Lucene.Net.Index.IndexReader" /> that
145  /// retrieved the <see cref="Document" /> is still open.
146  ///
147  /// </summary>
148  /// <value> true if this field can be loaded lazily </value>
149  bool IsLazy { get; }
150 
151  /// <summary> Returns offset into byte[] segment that is used as value, if Field is not binary
152  /// returned value is undefined
153  /// </summary>
154  /// <value> index of the first character in byte[] segment that represents this Field value </value>
155  int BinaryOffset { get; }
156 
157  /// <summary> Returns length of byte[] segment that is used as value, if Field is not binary
158  /// returned value is undefined
159  /// </summary>
160  /// <value> length of byte[] segment that represents this Field value </value>
161  int BinaryLength { get; }
162 
163  /// <summary> Return the raw byte[] for the binary field. Note that
164  /// you must also call <see cref="BinaryLength" /> and <see cref="BinaryOffset" />
165  /// to know which range of bytes in this
166  /// returned array belong to the field.
167  /// </summary>
168  /// <returns> reference to the Field value as byte[]. </returns>
169  byte[] GetBinaryValue();
170 
171  /// <summary> Return the raw byte[] for the binary field. Note that
172  /// you must also call <see cref="BinaryLength" /> and <see cref="BinaryOffset" />
173  /// to know which range of bytes in this
174  /// returned array belong to the field.<p/>
175  /// About reuse: if you pass in the result byte[] and it is
176  /// used, likely the underlying implementation will hold
177  /// onto this byte[] and return it in future calls to
178  /// <see cref="GetBinaryValue()" /> or <see cref="GetBinaryValue()" />.
179  /// So if you subsequently re-use the same byte[] elsewhere
180  /// it will alter this Fieldable's value.
181  /// </summary>
182  /// <param name="result"> User defined buffer that will be used if
183  /// possible. If this is null or not large enough, a new
184  /// buffer is allocated
185  /// </param>
186  /// <returns> reference to the Field value as byte[].
187  /// </returns>
188  byte[] GetBinaryValue(byte[] result);
189 
190  /// Expert:
191  /// <para>
192  /// If set, omit term freq, positions and payloads from
193  /// postings for this field.
194  /// </para>
195  /// <para>
196  /// <b>NOTE</b>: While this option reduces storage space
197  /// required in the index, it also means any query
198  /// requiring positional information, such as
199  /// <see cref="Lucene.Net.Search.PhraseQuery"/> or
200  /// <see cref="Lucene.Net.Search.Spans.SpanQuery"/>
201  /// subclasses will silently fail to find results.
202  /// </para>
203  bool OmitTermFreqAndPositions { set; get; }
204  }
205 }