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
FloatFieldSource.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 
20 using IndexReader = Lucene.Net.Index.IndexReader;
21 using FieldCache = Lucene.Net.Search.FieldCache;
22 
23 namespace Lucene.Net.Search.Function
24 {
25 
26  /// <summary> Expert: obtains float field values from the
27  /// <see cref="Lucene.Net.Search.FieldCache">FieldCache</see>
28  /// using <c>getFloats()</c> and makes those values
29  /// available as other numeric types, casting as needed.
30  ///
31  /// <p/><font color="#FF0000">
32  /// WARNING: The status of the <b>Search.Function</b> package is experimental.
33  /// The APIs introduced here might change in the future and will not be
34  /// supported anymore in such a case.</font>
35  ///
36  /// </summary>
37  /// <seealso cref="Lucene.Net.Search.Function.FieldCacheSource"> for requirements"
38  /// on the field.
39  ///
40  /// <p/><b>NOTE</b>: with the switch in 2.9 to segment-based
41  /// searching, if <see cref="FieldCacheSource.GetValues" /> is invoked with a
42  /// composite (multi-segment) reader, this can easily cause
43  /// double RAM usage for the values in the FieldCache. It's
44  /// best to switch your application to pass only atomic
45  /// (single segment) readers to this API.<p/>
46  /// </seealso>
47  [Serializable]
49  {
50  private class AnonymousClassDocValues:DocValues
51  {
52  public AnonymousClassDocValues(float[] arr, FloatFieldSource enclosingInstance)
53  {
54  InitBlock(arr, enclosingInstance);
55  }
56  private void InitBlock(float[] arr, FloatFieldSource enclosingInstance)
57  {
58  this.arr = arr;
59  this.enclosingInstance = enclosingInstance;
60  }
61  private float[] arr;
62  private FloatFieldSource enclosingInstance;
63  public FloatFieldSource Enclosing_Instance
64  {
65  get
66  {
67  return enclosingInstance;
68  }
69 
70  }
71  /*(non-Javadoc) <see cref="Lucene.Net.Search.Function.DocValues.floatVal(int) */
72  public override float FloatVal(int doc)
73  {
74  return arr[doc];
75  }
76  /*(non-Javadoc) <see cref="Lucene.Net.Search.Function.DocValues.toString(int) */
77  public override System.String ToString(int doc)
78  {
79  return Enclosing_Instance.Description() + '=' + arr[doc];
80  }
81  /*(non-Javadoc) <see cref="Lucene.Net.Search.Function.DocValues.getInnerArray() */
82 
83  protected internal override object InnerArray
84  {
85  get { return arr; }
86  }
87  }
88  private Lucene.Net.Search.FloatParser parser;
89 
90  /// <summary> Create a cached float field source with default string-to-float parser. </summary>
91  public FloatFieldSource(System.String field):this(field, null)
92  {
93  }
94 
95  /// <summary> Create a cached float field source with a specific string-to-float parser. </summary>
96  public FloatFieldSource(System.String field, Lucene.Net.Search.FloatParser parser):base(field)
97  {
98  this.parser = parser;
99  }
100 
101  /*(non-Javadoc) <see cref="Lucene.Net.Search.Function.ValueSource.description() */
102  public override System.String Description()
103  {
104  return "float(" + base.Description() + ')';
105  }
106 
107  /*(non-Javadoc) <see cref="Lucene.Net.Search.Function.FieldCacheSource.getCachedValues(Lucene.Net.Search.FieldCache, java.lang.String, Lucene.Net.Index.IndexReader) */
108  public override DocValues GetCachedFieldValues(FieldCache cache, System.String field, IndexReader reader)
109  {
110  float[] arr = cache.GetFloats(reader, field, parser);
111  return new AnonymousClassDocValues(arr, this);
112  }
113 
114  /*(non-Javadoc) <see cref="Lucene.Net.Search.Function.FieldCacheSource.cachedFieldSourceEquals(Lucene.Net.Search.Function.FieldCacheSource) */
115  public override bool CachedFieldSourceEquals(FieldCacheSource o)
116  {
117  if (o.GetType() != typeof(FloatFieldSource))
118  {
119  return false;
120  }
122  return this.parser == null?other.parser == null:this.parser.GetType() == other.parser.GetType();
123  }
124 
125  /*(non-Javadoc) <see cref="Lucene.Net.Search.Function.FieldCacheSource.cachedFieldSourceHashCode() */
126  public override int CachedFieldSourceHashCode()
127  {
128  return parser == null?typeof(System.Single).GetHashCode():parser.GetType().GetHashCode();
129  }
130  }
131 }