Thumbnail file hits. Based on a patch from D Bera
[beagle.git] / beagled / Lucene.Net / Index / Term.cs
blob6ecdd78d7b0afab0f265b5e54c2ff644f42f20a3
1 /*
2 * Copyright 2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 using System;
17 namespace Lucene.Net.Index
19 /// <summary>A Term represents a word from text. This is the unit of search. It is
20 /// composed of two elements, the text of the word, as a string, and the name of
21 /// the Field that the text occured in, an interned string.
22 /// Note that terms may represent more than words from text fields, but also
23 /// things like dates, email addresses, urls, etc.
24 /// </summary>
25 [Serializable]
26 public sealed class Term : System.IComparable
28 internal System.String field;
29 public /*internal*/ System.String text;
31 /// <summary>Constructs a Term with the given Field and text. </summary>
32 public Term(System.String fld, System.String txt) : this(fld, txt, true)
35 internal Term(System.String fld, System.String txt, bool intern)
37 field = intern ? String.Intern(fld) : fld; // Field names are interned
38 text = txt; // unless already known to be
41 /// <summary>Returns the Field of this term, an interned string. The Field indicates
42 /// the part of a document which this term came from.
43 /// </summary>
44 public System.String Field()
46 return field;
49 /// <summary>Returns the text of this term. In the case of words, this is simply the
50 /// text of the word. In the case of dates and other types, this is an
51 /// encoding of the object as a string.
52 /// </summary>
53 public System.String Text()
55 return text;
58 /// <summary>Compares two terms, returning true iff they have the same
59 /// Field and text.
60 /// </summary>
61 public override bool Equals(System.Object o)
63 if (o == null)
64 return false;
65 Term other = (Term) o;
66 return (System.Object) field == (System.Object) other.field && text.Equals(other.text);
69 /// <summary>Combines the hashCode() of the Field and the text. </summary>
70 public override int GetHashCode()
72 return field.GetHashCode() + text.GetHashCode();
75 public int CompareTo(System.Object other)
77 return CompareTo((Term) other);
80 /// <summary>Compares two terms, returning an integer which is less than zero iff this
81 /// term belongs after the argument, equal zero iff this term is equal to the
82 /// argument, and greater than zero iff this term belongs after the argument.
83 /// The ordering of terms is first by Field, then by text.
84 /// </summary>
85 public int CompareTo(Term other)
87 if ((System.Object) field == (System.Object) other.field)
88 // fields are interned
89 return String.CompareOrdinal(text, other.text);
90 else
91 return String.CompareOrdinal(field, other.field);
94 /// <summary>Resets the Field and text of a Term. </summary>
95 internal void Set(System.String fld, System.String txt)
97 field = String.Intern(fld); // FIXED(?) trow@novell.com on May 24, 2005
98 text = txt;
101 public override System.String ToString()
103 return field + ":" + text;
106 private void ReadObject(System.IO.BinaryReader in_Renamed)
108 // This function is private and is never been called, so this may not be a port issue. // {{Aroush}}
109 // in_Renamed.defaultReadObject(); // {{Aroush}} >> 'java.io.ObjectInputStream.defaultReadObject()'
110 field = String.Intern(field);
113 // {{Aroush: Or is this what we want (vs. the above)?!!
114 private void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
116 info.AddValue("field", field);
117 info.AddValue("text", text);
119 // Aroush}}