4 // Copyright (C) 2004 Novell, Inc.
8 // Permission is hereby granted, free of charge, to any person obtaining a
9 // copy of this software and associated documentation files (the "Software"),
10 // to deal in the Software without restriction, including without limitation
11 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 // and/or sell copies of the Software, and to permit persons to whom the
13 // Software is furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 // DEALINGS IN THE SOFTWARE.
28 using System
.Xml
.Serialization
;
34 public enum PropertyType
{
40 public class Property
: IComparable
, ICloneable
{
50 public PropertyType Type
{
58 set { this.key = StringFu.CleanupInvalidXmlCharacters (value); }
64 set { this.value = StringFu.CleanupInvalidXmlCharacters (value); }
67 // If IsSearched is true, this property will can be matched by a
68 // general match-any-propety query.
69 // You can always query against the specific property, even if
70 // IsSearched is false.
72 public bool IsSearched
{
73 get { return is_searched; }
74 set { is_searched = value; }
77 // When IsMutable is true, the property is stored in the secondary
78 // index so that it can more efficiently be changed later on.
80 public bool IsMutable
{
81 get { return is_mutable; }
82 set { is_mutable = value; }
85 // When IsStored is false, the property will be stored as an "unstored lucene field".
87 public bool IsStored
{
88 get { return is_stored; }
89 set { is_stored = value; }
92 /////////////////////////////////////
94 public Property () { }
96 public int CompareTo (object other
)
98 // By convention, a non-null object always
99 // compares greater than null.
103 Property other_property
= other
as Property
;
105 // If the other object is not a Property, compare the
106 // two objects by their hash codes.
107 if (other_property
== null)
108 return this.GetHashCode ().CompareTo (other
.GetHashCode ());
111 rv
= String
.Compare (this.Key
, other_property
.Key
);
115 return String
.Compare (this.Value
, other_property
.Value
);
118 public object Clone ()
120 return this.MemberwiseClone ();
123 static public Property
New (string key
, string value)
128 Property p
= new Property ();
129 p
.type
= PropertyType
.Text
;
132 p
.is_searched
= true;
137 static public Property
NewKeyword (string key
, object value)
142 Property p
= new Property ();
143 p
.type
= PropertyType
.Keyword
;
145 p
.Value
= value.ToString ();
146 p
.is_searched
= true;
151 static public Property
NewUnsearched (string key
, object value)
156 Property p
= new Property ();
157 p
.type
= PropertyType
.Keyword
;
159 p
.Value
= value.ToString ();
160 p
.is_searched
= false;
165 static public Property
NewUnstored (string key
, object value)
170 Property p
= new Property ();
171 p
.type
= PropertyType
.Text
;
173 p
.Value
= value.ToString ();
174 p
.is_searched
= true;
179 static public Property
NewBool (string key
, bool value)
181 return Property
.NewUnsearched (key
, value ? "true" : "false");
184 static public Property
NewFlag (string key
)
186 return NewBool (key
, true);
189 static public Property
NewDate (string key
, DateTime dt
)
191 Property p
= new Property ();
192 p
.type
= PropertyType
.Date
;
194 p
.Value
= StringFu
.DateTimeToString (dt
);
195 p
.is_searched
= true;
200 static public Property
NewDateFromString (string key
, string value)
205 Property p
= new Property ();
206 p
.type
= PropertyType
.Date
;
208 // FIXME: Should probably check that value is a valid date string.
210 p
.is_searched
= true;
215 override public string ToString ()
217 return String
.Format ("{0}={1}", Key
, Value
);