FilterHtml.cs: Add ExtractText(string) command to extract text out of large html...
[beagle.git] / beagled / IndexerRequest.cs
blob352b6eeaa714166aa0acc48719670b5de3a5516e
1 //
2 // IndexerRequest.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.
27 using System;
28 using System.Collections;
29 using System.Xml.Serialization;
31 using Beagle.Util;
33 namespace Beagle.Daemon {
35 public class IndexerRequest {
37 public bool OptimizeIndex = false;
39 private Hashtable indexables_by_uri = UriFu.NewHashtable ();
40 private ArrayList indexables = null;
42 // FIXME: We don't try to keep the ArrayList and the Hashtable
43 // in-sync. This is a hack to make XML serialization work easily,
44 // and it assumes that an IndexerRequest is never changed after
45 // it has been serialized.
47 public void Clear ()
49 OptimizeIndex = false;
50 indexables_by_uri.Clear ();
51 indexables = null;
54 public void Add (Indexable indexable)
56 if (indexables != null)
57 throw new Exception ("Attempt to add to a serialized IndexerRequest");
59 if (indexable == null)
60 return;
62 Indexable prior;
63 prior = indexables_by_uri [indexable.Uri] as Indexable;
65 if (prior != null) {
67 switch (indexable.Type) {
69 case IndexableType.Add:
70 case IndexableType.Remove:
71 // Do nothing, and just clobber the prior indexable.
72 break;
74 case IndexableType.PropertyChange:
75 // Merge with the prior indexable.
76 prior.Merge (indexable);
77 indexable = prior;
78 break;
82 indexables_by_uri [indexable.Uri] = indexable;
85 public Indexable GetByUri (Uri uri)
87 if (indexables_by_uri != null)
88 return indexables_by_uri [uri] as Indexable;
90 // Fall back to using the list. This happens when we
91 // have been serialized. Which is sort of lame.
92 foreach (Indexable indexable in indexables) {
93 if (UriFu.Equals (uri, indexable.Uri))
94 return indexable;
96 return null;
99 [XmlArray (ElementName="Indexables")]
100 [XmlArrayItem (ElementName="Indexable", Type=typeof (Indexable))]
101 public ArrayList Indexables {
102 get {
103 if (indexables == null) {
104 indexables = new ArrayList ();
105 foreach (Indexable indexable in indexables_by_uri.Values)
106 indexables.Add (indexable);
107 indexables.Sort (); // sort into ascending timestamp order
109 return indexables;
113 [XmlIgnore]
114 public int Count {
115 get { return indexables != null ? indexables.Count : indexables_by_uri.Count; }
118 [XmlIgnore]
119 public bool IsEmpty {
120 get { return Count == 0 && ! OptimizeIndex; }
123 public void Cleanup ()
125 if (indexables_by_uri != null)
126 foreach (Indexable i in indexables_by_uri.Values)
127 i.Cleanup ();
128 else
129 foreach (Indexable i in indexables)
130 i.Cleanup ();