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
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 
40  [Serializable]
41  public class FieldDoc:ScoreDoc
42  {
43 
53  [NonSerialized]
54  public System.IComparable[] fields;
55 
57  public FieldDoc(int doc, float score):base(doc, score)
58  {
59  }
60 
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 }