Merge pull request #409 from Alkarex/patch-1
[mono.git] / mcs / tools / monkeydoc / Lucene.Net / Lucene.Net / Search / Function / FieldCacheSource.cs
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 = Mono.Lucene.Net.Index.IndexReader;
21 using FieldCache = Mono.Lucene.Net.Search.FieldCache;
22
23 namespace Mono.Lucene.Net.Search.Function
24 {
25         
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}.
28         /// <p/>
29         /// Fields used herein nust be indexed (doesn't matter if these fields are stored or not).
30         /// <p/> 
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).
34         /// <p/>
35         /// Document with no tokens in this field are assigned the <code>Zero</code> value.    
36         /// 
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>
41         /// 
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/>
51         /// </summary>
52         [Serializable]
53         public abstract class FieldCacheSource:ValueSource
54         {
55                 private System.String field;
56                 
57                 /// <summary> Create a cached field source for the input field.  </summary>
58                 public FieldCacheSource(System.String field)
59                 {
60                         this.field = field;
61                 }
62                 
63                 /* (non-Javadoc) @see Mono.Lucene.Net.Search.Function.ValueSource#getValues(Mono.Lucene.Net.Index.IndexReader) */
64                 public override DocValues GetValues(IndexReader reader)
65                 {
66                         return GetCachedFieldValues(Mono.Lucene.Net.Search.FieldCache_Fields.DEFAULT, field, reader);
67                 }
68                 
69                 /* (non-Javadoc) @see Mono.Lucene.Net.Search.Function.ValueSource#description() */
70                 public override System.String Description()
71                 {
72                         return field;
73                 }
74                 
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)
77                 /// </param>
78                 /// <param name="field">Field for which values are required.
79                 /// </param>
80                 /// <seealso cref="ValueSource">
81                 /// </seealso>
82                 public abstract DocValues GetCachedFieldValues(FieldCache cache, System.String field, IndexReader reader);
83                 
84                 /*(non-Javadoc) @see java.lang.Object#equals(java.lang.Object) */
85                 public  override bool Equals(System.Object o)
86                 {
87                         if (!(o is FieldCacheSource))
88                         {
89                                 return false;
90                         }
91                         FieldCacheSource other = (FieldCacheSource) o;
92                         return this.field.Equals(other.field) && CachedFieldSourceEquals(other);
93                 }
94                 
95                 /*(non-Javadoc) @see java.lang.Object#hashCode() */
96                 public override int GetHashCode()
97                 {
98                         return field.GetHashCode() + CachedFieldSourceHashCode();
99                 }
100                 
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)">
103                 /// </seealso>
104                 public abstract bool CachedFieldSourceEquals(FieldCacheSource other);
105                 
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).  
108                 /// </summary>
109                 /// <seealso cref="Object.hashCode()">
110                 /// </seealso>
111                 public abstract int CachedFieldSourceHashCode();
112         }
113 }