Thumbnail file hits. Based on a patch from D Bera
[beagle.git] / beagled / IndexingServiceQueryable / IndexingServiceQueryable.cs
blob88a6d9b8e1a506aa74b9f8313382d10a47823dbb
1 //
2 // IndexingServiceQueryable.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;
30 using Beagle.Daemon;
31 using Beagle.Util;
33 namespace Beagle.Daemon.IndexingServiceQueryable {
35 [QueryableFlavor (Name="IndexingService", Domain=QueryDomain.Local, RequireInotify=false)]
36 public class IndexingServiceQueryable : LuceneQueryable {
38 public IndexingServiceQueryable () : base ("IndexingServiceIndex")
40 Server.RegisterRequestMessageHandler (typeof (IndexingServiceRequest), new Server.RequestMessageHandler (HandleMessage));
43 private class IndexableGenerator : IIndexableGenerator {
44 private IEnumerator to_add_enumerator;
45 private int count, done_count = 0;
47 public IndexableGenerator (ICollection to_add)
49 this.count = to_add.Count;
50 this.to_add_enumerator = to_add.GetEnumerator ();
53 public Indexable GetNextIndexable ()
55 return to_add_enumerator.Current as Indexable;
58 public bool HasNextIndexable ()
60 ++done_count;
61 return to_add_enumerator.MoveNext ();
64 public string StatusName {
65 get { return String.Format ("IndexingService: {0} of {1}", done_count, count); }
69 private ResponseMessage HandleMessage (RequestMessage msg)
71 IndexingServiceRequest isr = (IndexingServiceRequest) msg;
73 foreach (Uri uri in isr.ToRemove) {
74 Scheduler.Task task = NewRemoveTask (uri);
75 ThisScheduler.Add (task);
78 // FIXME: There should be a way for the request to control the
79 // scheduler priority of the task.
81 if (isr.ToAdd.Count > 0) {
82 IIndexableGenerator ind_gen = new IndexableGenerator (isr.ToAdd);
83 Scheduler.Task task = NewAddTask (ind_gen);
84 task.Priority = Scheduler.Priority.Immediate;
85 ThisScheduler.Add (task);
88 // FIXME: There should be an asynchronous response (fired by a Scheduler.Hook)
89 // that fires when all of the items have been added to the index.
91 // No response
92 return new EmptyResponse ();