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
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 
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 
91  public FloatFieldSource(System.String field):this(field, null)
92  {
93  }
94 
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 }