4 // Copyright (C) 2005 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.
30 using System
.Collections
;
32 using System
.Xml
.Serialization
;
34 using BU
= Beagle
.Util
;
38 public enum QueryPartLogic
{
43 [XmlInclude (typeof (QueryPart_Text
)),
44 XmlInclude (typeof (QueryPart_Property
)),
45 XmlInclude (typeof (QueryPart_DateRange
)),
46 XmlInclude (typeof (QueryPart_Human
)),
47 XmlInclude (typeof (QueryPart_Wildcard
)),
48 XmlInclude (typeof (QueryPart_Or
))]
49 abstract public class QueryPart
{
51 private QueryPartLogic logic
= QueryPartLogic
.Required
;
56 public QueryPartLogic Logic
{
58 set { logic = value; }
61 public override string ToString ()
63 return String
.Format ("{0}:\n Logic: {1}\n", this.GetType (), Logic
);
67 public class QueryPart_Text
: QueryPart
{
70 private bool search_full_text
= true;
71 private bool search_properties
= true;
73 public QueryPart_Text ()
81 public bool SearchFullText
{
82 get { return search_full_text; }
83 set { search_full_text = value; }
86 public bool SearchTextProperties
{
87 get { return search_properties; }
88 set { search_properties = value; }
91 public override string ToString ()
93 return String
.Format (
96 " Search full text: {1}\n" +
97 " Search text properties: {2}",
98 Text
, SearchFullText
, SearchTextProperties
);
102 // AllProperties queries are not allowed on keywords.
103 public class QueryPart_Property
: QueryPart
{
105 public const string AllProperties
= "_all";
107 private PropertyType type
;
109 private string value;
111 public QueryPart_Property ()
114 public PropertyType Type
{
116 set { type = value; }
124 public string Value
{
125 get { return value; }
126 set { this.value = value; }
// ugh
129 public override string ToString ()
131 return String
.Format (
140 public class QueryPart_DateRange
: QueryPart
{
142 public const string AllPropertiesKey
= "_all";
143 public const string TimestampKey
= "Timestamp";
145 private string key
= AllPropertiesKey
;
146 private DateTime start_date
;
147 private DateTime end_date
;
149 public QueryPart_DateRange ()
157 public DateTime StartDate
{
158 get { return start_date; }
159 set { start_date = value; }
162 public DateTime EndDate
{
163 get { return end_date; }
164 set { end_date = value; }
167 public override string ToString ()
169 return String
.Format (
172 " Start date: {1}\n" +
174 Key
, StartDate
, EndDate
);
178 public class QueryPart_Human
: QueryPart
{
180 private string query_string
;
182 public QueryPart_Human ()
185 public string QueryString
{
186 get { return query_string; }
187 set { query_string = value; }
190 public override string ToString ()
192 return String
.Format (
199 public class QueryPart_Wildcard
: QueryPart
{
201 private string query_string
;
203 public QueryPart_Wildcard ()
206 public string QueryString
{
207 get { return query_string; }
208 set { query_string = value; }
211 public override string ToString ()
213 return String
.Format (
220 public class QueryPart_Or
: QueryPart
{
222 private ArrayList sub_parts
= new ArrayList ();
224 public QueryPart_Or ()
227 [XmlArray ("SubParts")]
228 [XmlArrayItem (ElementName
="Part", Type
=typeof (QueryPart
))]
229 public ArrayList SubParts_ShouldBePrivateSoPleaseDontUseThis
{
230 get { return sub_parts; }
234 public ICollection SubParts
{
235 get { return sub_parts; }
238 // FIXME: Really the only thing that is allowed as a subpart
239 // of an 'Or' part are required (not prohibited) text or
240 // property queries. We should be clearer about the rules,
242 public void Add (QueryPart part
)
244 sub_parts
.Add (part
);
247 public override string ToString ()
249 StringBuilder sb
= new StringBuilder (base.ToString ());
251 foreach (QueryPart p
in sub_parts
)
252 sb
.Append (" " + p
.ToString () + "\n");
254 return sb
.ToString ();