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
FieldDoc.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 namespace Lucene.Net.Search
21 {
22 
23  /// <summary> Expert: A ScoreDoc which also contains information about
24  /// how to sort the referenced document. In addition to the
25  /// document number and score, this object contains an array
26  /// of values for the document from the field(s) used to sort.
27  /// For example, if the sort criteria was to sort by fields
28  /// "a", "b" then "c", the <c>fields</c> object array
29  /// will have three elements, corresponding respectively to
30  /// the term values for the document in fields "a", "b" and "c".
31  /// The class of each element in the array will be either
32  /// Integer, Float or String depending on the type of values
33  /// in the terms of each field.
34  ///
35  /// <p/>Created: Feb 11, 2004 1:23:38 PM
36  ///
37  /// </summary>
38  /// <seealso cref="ScoreDoc"></seealso>
39  /// <seealso cref="TopFieldDocs"></seealso>
40  [Serializable]
41  public class FieldDoc:ScoreDoc
42  {
43 
44  /// <summary>Expert: The values which are used to sort the referenced document.
45  /// The order of these will match the original sort criteria given by a
46  /// Sort object. Each Object will be either an Integer, Float or String,
47  /// depending on the type of values in the terms of the original field.
48  /// </summary>
49  /// <seealso cref="Sort">
50  /// </seealso>
51  /// <seealso cref="Searcher.Search(Query,Filter,int,Sort)">
52  /// </seealso>
53  [NonSerialized]
54  public System.IComparable[] fields;
55 
56  /// <summary>Expert: Creates one of these objects with empty sort information. </summary>
57  public FieldDoc(int doc, float score):base(doc, score)
58  {
59  }
60 
61  /// <summary>Expert: Creates one of these objects with the given sort information. </summary>
62  public FieldDoc(int doc, float score, System.IComparable[] fields):base(doc, score)
63  {
64  this.fields = fields;
65  }
66 
67  // A convenience method for debugging.
68  public override System.String ToString()
69  {
70  // super.toString returns the doc and score information, so just add the
71  // fields information
72  System.Text.StringBuilder sb = new System.Text.StringBuilder(base.ToString());
73  sb.Append("[");
74  for (int i = 0; i < fields.Length; i++)
75  {
76  sb.Append(fields[i]).Append(", ");
77  }
78  sb.Length -= 2; // discard last ", "
79  sb.Append("]");
80  return sb.ToString();
81  }
82 
83  #region SERIALIZATION
84  internal object[] fieldsClone = null;
85 
86  [System.Runtime.Serialization.OnSerializing]
87  void OnSerializing(System.Runtime.Serialization.StreamingContext context)
88  {
89  if (fields == null) return;
90 
91  // Copy "fields" to "fieldsClone"
92  fieldsClone = new object[fields.Length];
93  for (int i = 0; i < fields.Length; i++)
94  {
95  fieldsClone[i] = fields[i];
96  }
97  }
98 
99  [System.Runtime.Serialization.OnDeserialized]
100  void OnDeserialized(System.Runtime.Serialization.StreamingContext context)
101  {
102  if (fieldsClone == null) return;
103 
104  // Form "fields" from "fieldsClone"
105  fields = new IComparable[fieldsClone.Length];
106  for (int i = 0; i < fields.Length; i++)
107  {
108  fields[i] = (IComparable)fieldsClone[i];
109  }
110  }
111  #endregion
112  }
113 }