Lucene.Net  3.0.3
Lucene.Net is a .NET port of the Java Lucene Indexing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties
NumericField.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 Lucene.Net.Search;
21 using NumericTokenStream = Lucene.Net.Analysis.NumericTokenStream;
22 using TokenStream = Lucene.Net.Analysis.TokenStream;
23 using NumericUtils = Lucene.Net.Util.NumericUtils;
24 using FieldCache = Lucene.Net.Search.FieldCache;
25 using SortField = Lucene.Net.Search.SortField;
26 
27 namespace Lucene.Net.Documents
28 {
29  // javadocs
30 
144  [Serializable]
145  public sealed class NumericField:AbstractField
146  {
147 
148  new private readonly NumericTokenStream tokenStream;
149 
158  public NumericField(System.String name):this(name, NumericUtils.PRECISION_STEP_DEFAULT, Field.Store.NO, true)
159  {
160  }
161 
174  public NumericField(System.String name, Field.Store store, bool index):this(name, NumericUtils.PRECISION_STEP_DEFAULT, store, index)
175  {
176  }
177 
188  public NumericField(System.String name, int precisionStep):this(name, precisionStep, Field.Store.NO, true)
189  {
190  }
191 
206  public NumericField(System.String name, int precisionStep, Field.Store store, bool index):base(name, store, index?Field.Index.ANALYZED_NO_NORMS:Field.Index.NO, Field.TermVector.NO)
207  {
208  OmitTermFreqAndPositions = true;
209  tokenStream = new NumericTokenStream(precisionStep);
210  }
211 
213  public override TokenStream TokenStreamValue
214  {
215  get { return IsIndexed ? tokenStream : null; }
216  }
217 
219  public override byte[] GetBinaryValue(byte[] result)
220  {
221  return null;
222  }
223 
225  public override TextReader ReaderValue
226  {
227  get { return null; }
228  }
229 
231  public override string StringValue
232  {
233  get { return (fieldsData == null) ? null : fieldsData.ToString(); }
234  }
235 
237  public ValueType NumericValue
238  {
239  get { return (System.ValueType) fieldsData; }
240  }
241 
248  public NumericField SetLongValue(long value_Renamed)
249  {
250  tokenStream.SetLongValue(value_Renamed);
251  fieldsData = value_Renamed;
252  return this;
253  }
254 
261  public NumericField SetIntValue(int value_Renamed)
262  {
263  tokenStream.SetIntValue(value_Renamed);
264  fieldsData = value_Renamed;
265  return this;
266  }
267 
274  public NumericField SetDoubleValue(double value_Renamed)
275  {
276  tokenStream.SetDoubleValue(value_Renamed);
277  fieldsData = value_Renamed;
278  return this;
279  }
280 
287  public NumericField SetFloatValue(float value_Renamed)
288  {
289  tokenStream.SetFloatValue(value_Renamed);
290  fieldsData = value_Renamed;
291  return this;
292  }
293  }
294 }