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.
19 namespace Lucene
.Net
.Index
22 /// <summary>A Term represents a word from text. This is the unit of search. It is
23 /// composed of two elements, the text of the word, as a string, and the name of
24 /// the field that the text occured in, an interned string.
25 /// Note that terms may represent more than words from text fields, but also
26 /// things like dates, email addresses, urls, etc.
30 public sealed class Term
: System
.IComparable
32 internal System
.String field
;
33 public /*internal*/ System
.String text
;
35 /// <summary>Constructs a Term with the given field and text. </summary>
36 public Term(System
.String fld
, System
.String txt
) : this(fld
, txt
, true)
39 internal Term(System
.String fld
, System
.String txt
, bool intern
)
41 field
= intern
? String
.Intern(fld
) : fld
; // field names are interned
42 text
= txt
; // unless already known to be
45 /// <summary>Returns the field of this term, an interned string. The field indicates
46 /// the part of a document which this term came from.
48 public System
.String
Field()
53 /// <summary>Returns the text of this term. In the case of words, this is simply the
54 /// text of the word. In the case of dates and other types, this is an
55 /// encoding of the object as a string.
57 public System
.String
Text()
62 /// <summary> Optimized construction of new Terms by reusing same field as this Term
63 /// - avoids field.intern() overhead
65 /// <param name="text">The text of the new term (field is implicitly same as this Term instance)
67 /// <returns> A new Term
69 public Term
CreateTerm(System
.String text
)
71 return new Term(field
, text
, false);
74 /// <summary>Compares two terms, returning true iff they have the same
77 public override bool Equals(System
.Object o
)
81 Term other
= (Term
) o
;
82 return field
== other
.field
&& text
.Equals(other
.text
);
85 /// <summary>Combines the hashCode() of the field and the text. </summary>
86 public override int GetHashCode()
88 return field
.GetHashCode() + text
.GetHashCode();
91 public int CompareTo(System
.Object other
)
93 return CompareTo((Term
) other
);
96 /// <summary>Compares two terms, returning a negative integer if this
97 /// term belongs before the argument, zero if this term is equal to the
98 /// argument, and a positive integer if this term belongs after the argument.
99 /// The ordering of terms is first by field, then by text.
101 public int CompareTo(Term other
)
103 if (field
== other
.field
)
104 // fields are interned
105 return String
.CompareOrdinal(text
, other
.text
);
107 return String
.CompareOrdinal(field
, other
.field
);
110 /// <summary>Resets the field and text of a Term. </summary>
111 internal void Set(System
.String fld
, System
.String txt
)
117 public override System
.String
ToString()
119 return field
+ ":" + text
;
122 private void ReadObject(System
.IO
.BinaryReader in_Renamed
)
124 // This function is private and is never been called, so this may not be a port issue. // {{Aroush-1.4.3}}
125 // 'java.io.ObjectInputStream.defaultReadObject' was not converted // {{Aroush-1.4.3}}
126 // in_Renamed.defaultReadObject(); // {{Aroush-1.4.3}}
127 field
= String
.Intern(field
);
130 // {{Aroush-1.4.3: or is this method is what we want (vs. the above)?!!
131 private void GetObjectData(System
.Runtime
.Serialization
.SerializationInfo info
, System
.Runtime
.Serialization
.StreamingContext context
)
133 info
.AddValue("field", field
);
134 info
.AddValue("text", text
);