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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 using IndexReader = Mono.Lucene.Net.Index.IndexReader;
21 using FieldCache = Mono.Lucene.Net.Search.FieldCache;
23 namespace Mono.Lucene.Net.Search.Function
26 /// <summary> Expert: A base class for ValueSource implementations that retrieve values for
27 /// a single field from the {@link Mono.Lucene.Net.Search.FieldCache FieldCache}.
29 /// Fields used herein nust be indexed (doesn't matter if these fields are stored or not).
31 /// It is assumed that each such indexed field is untokenized, or at least has a single token in a document.
32 /// For documents with multiple tokens of the same field, behavior is undefined (It is likely that current
33 /// code would use the value of one of these tokens, but this is not guaranteed).
35 /// Document with no tokens in this field are assigned the <code>Zero</code> value.
37 /// <p/><font color="#FF0000">
38 /// WARNING: The status of the <b>Search.Function</b> package is experimental.
39 /// The APIs introduced here might change in the future and will not be
40 /// supported anymore in such a case.</font>
42 /// <p/><b>NOTE</b>: with the switch in 2.9 to segment-based
43 /// searching, if {@link #getValues} is invoked with a
44 /// composite (multi-segment) reader, this can easily cause
45 /// double RAM usage for the values in the FieldCache. It's
46 /// best to switch your application to pass only atomic
47 /// (single segment) readers to this API. Alternatively, for
48 /// a short-term fix, you could wrap your ValueSource using
49 /// {@link MultiValueSource}, which costs more CPU per lookup
50 /// but will not consume double the FieldCache RAM.<p/>
53 public abstract class FieldCacheSource:ValueSource
55 private System.String field;
57 /// <summary> Create a cached field source for the input field. </summary>
58 public FieldCacheSource(System.String field)
63 /* (non-Javadoc) @see Mono.Lucene.Net.Search.Function.ValueSource#getValues(Mono.Lucene.Net.Index.IndexReader) */
64 public override DocValues GetValues(IndexReader reader)
66 return GetCachedFieldValues(Mono.Lucene.Net.Search.FieldCache_Fields.DEFAULT, field, reader);
69 /* (non-Javadoc) @see Mono.Lucene.Net.Search.Function.ValueSource#description() */
70 public override System.String Description()
75 /// <summary> Return cached DocValues for input field and reader.</summary>
76 /// <param name="cache">FieldCache so that values of a field are loaded once per reader (RAM allowing)
78 /// <param name="field">Field for which values are required.
80 /// <seealso cref="ValueSource">
82 public abstract DocValues GetCachedFieldValues(FieldCache cache, System.String field, IndexReader reader);
84 /*(non-Javadoc) @see java.lang.Object#equals(java.lang.Object) */
85 public override bool Equals(System.Object o)
87 if (!(o is FieldCacheSource))
91 FieldCacheSource other = (FieldCacheSource) o;
92 return this.field.Equals(other.field) && CachedFieldSourceEquals(other);
95 /*(non-Javadoc) @see java.lang.Object#hashCode() */
96 public override int GetHashCode()
98 return field.GetHashCode() + CachedFieldSourceHashCode();
101 /// <summary> Check if equals to another {@link FieldCacheSource}, already knowing that cache and field are equal. </summary>
102 /// <seealso cref="Object.equals(java.lang.Object)">
104 public abstract bool CachedFieldSourceEquals(FieldCacheSource other);
106 /// <summary> Return a hash code of a {@link FieldCacheSource}, without the hash-codes of the field
107 /// and the cache (those are taken care of elsewhere).
109 /// <seealso cref="Object.hashCode()">
111 public abstract int CachedFieldSourceHashCode();