Forgot to bump FSQ version. Weekend syndrome.
[beagle.git] / BeagleClient / QueryPart.cs
blobbc30e0cf018c20bd6eb5ad1fe0a20075b9c4b6c4
1 //
2 // QueryPart.cs
3 //
4 // Copyright (C) 2005 Novell, Inc.
5 //
7 //
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;
29 using System.IO;
30 using System.Collections;
31 using System.Xml.Serialization;
33 using BU = Beagle.Util;
35 namespace Beagle {
37 public enum QueryPartLogic {
38 Required = 1,
39 Prohibited = 2
42 [XmlInclude (typeof (QueryPart_Text)),
43 XmlInclude (typeof (QueryPart_Property)),
44 XmlInclude (typeof (QueryPart_DateRange)),
45 XmlInclude (typeof (QueryPart_Human)),
46 XmlInclude (typeof (QueryPart_Or))]
47 abstract public class QueryPart {
49 private QueryPartLogic logic = QueryPartLogic.Required;
51 public QueryPart ()
52 { }
54 public QueryPartLogic Logic {
55 get { return logic; }
56 set { logic = value; }
60 public class QueryPart_Text : QueryPart {
62 private string text;
63 private bool search_full_text = true;
64 private bool search_properties = true;
66 public QueryPart_Text ()
67 { }
69 public string Text {
70 get { return text; }
71 set { text = value; }
74 public bool SearchFullText {
75 get { return search_full_text; }
76 set { search_full_text = value; }
79 public bool SearchTextProperties {
80 get { return search_properties; }
81 set { search_properties = value; }
85 // AllProperties queries are not allowed on keywords.
86 public class QueryPart_Property : QueryPart {
88 public const string AllProperties = "_all";
90 private PropertyType type;
91 private string key;
92 private string value;
94 public QueryPart_Property ()
95 { }
97 public PropertyType Type {
98 get { return type; }
99 set { type = value; }
102 public string Key {
103 get { return key; }
104 set { key = value; }
107 public string Value {
108 get { return value; }
109 set { this.value = value; } // ugh
113 public class QueryPart_DateRange : QueryPart {
115 public const string AllPropertiesKey = "_all";
116 public const string TimestampKey = "Timestamp";
118 private string key = AllPropertiesKey;
119 private DateTime start_date;
120 private DateTime end_date;
122 public QueryPart_DateRange ()
125 public string Key {
126 get { return key; }
127 set { key = value; }
130 public DateTime StartDate {
131 get { return start_date; }
132 set { start_date = value; }
135 public DateTime EndDate {
136 get { return end_date; }
137 set { end_date = value; }
141 public class QueryPart_Human : QueryPart {
143 private string query_string;
145 public QueryPart_Human ()
148 public string QueryString {
149 get { return query_string; }
150 set { query_string = value; }
154 public class QueryPart_Or : QueryPart {
156 private ArrayList sub_parts = new ArrayList ();
158 public QueryPart_Or ()
161 [XmlArray ("SubParts")]
162 [XmlArrayItem (ElementName="Part", Type=typeof (QueryPart))]
163 public ArrayList SubParts_ShouldBePrivateSoPleaseDontUseThis {
164 get { return sub_parts; }
167 [XmlIgnore]
168 public ICollection SubParts {
169 get { return sub_parts; }
172 // FIXME: Really the only thing that is allowed as a subpart
173 // of an 'Or' part are required (not prohibited) text or
174 // property queries. We should be clearer about the rules,
175 // and enforce them.
176 public void Add (QueryPart part)
178 sub_parts.Add (part);