2 * Copyright 2004 The Apache Software Foundation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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.
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.
44 public System
.String
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.
53 public System
.String
Text()
58 /// <summary>Compares two terms, returning true iff they have the same
61 public override bool Equals(System
.Object o
)
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.
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
);
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
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
);