public BeaglePlugin() { server = Daemon.Server; db = Daemon.DefaultDatabase; log = Daemon.Log; query = new Query (); query.AddDomain (QueryDomain.Neighborhood); query.MaxHits = 10000; QueryPart_Property filePart = new QueryPart_Property (); filePart.Type = PropertyType.Keyword; filePart.Key = "beagle:HitType"; filePart.Value = "File"; query.AddPart (filePart); QueryPart_Or queryUnion = new QueryPart_Or (); foreach (string mt in supportedMimeTypes) { QueryPart_Property part = new QueryPart_Property (); part.Type = PropertyType.Keyword; part.Key = "beagle:MimeType"; part.Value = mt; queryUnion.Add (part); } query.AddPart (queryUnion); query.HitsAddedEvent += OnHitsAdded; query.HitsSubtractedEvent += OnHitsSubtracted; query.FinishedEvent += OnFinished; int attempts = 0; while (true) { try { query.SendAsync (); break; } catch (Exception e) { if (attempts++ >= 5) { log.Warn ("Failed to initialize beagle plugin"); query = null; break; } // something bad happened, wait a sec and try again log.Debug ("Sending query failed: " + e.Message); log.Debug ("Waiting 3 seconds..."); Thread.Sleep (3000); } } }
public string doQuery(webArgs wargs) { if (wargs.sessId == null || wargs.searchString == null || wargs.searchString == "") return NO_RESULTS; log.Debug("WebBackEnd: Got Search String: " + wargs.searchString); Query query = new Query(); query.AddText (wargs.searchString); if (wargs.searchSource != null && wargs.searchSource != "") { query.AddSource(wargs.searchSource); query.AddDomain(QueryDomain.System); } else query.AddDomain (wargs.globalSearch ? QueryDomain.Global:QueryDomain.System); QueryResult qres = new QueryResult (); //Note: QueryDriver.DoQuery() local invocation is used. //The root tile is used only for adding hits and generating html. BT.SimpleRootTile root = new BT.SimpleRootTile (); root.Query = query; //root.SetSource (searchSource); Do not SetSource on root! ResultPair rp = new ResultPair(root); bufferRenderContext bctx = new bufferRenderContext(rp); Resp resp = new Resp(rp, bctx, wargs.isLocalReq); AttachQueryResult (qres, resp); //Add sessionId-Resp mapping if (sessionResp.Contains(wargs.sessId)) sessionResp[wargs.sessId] = resp; else sessionResp.Add(wargs.sessId, resp); log.Info("WebBackEnd: Starting Query for string \"{0}\"", wargs.searchString); QueryDriver.DoQueryLocal (query, qres); //Wait only till we have enough results to display while ((result.Contains(qres)) && (root.HitCollection.NumResults < 10)) Thread.Sleep(100); if (root.HitCollection.IsEmpty) return NO_RESULTS; lock (root) { root.Render(bctx); return (getResultsLabel(root) + (wargs.isLocalReq ? bctx.buffer:bctx.bufferForExternalQuery)); } }
private void Search (String searchString) { entry.Text = searchString; StoreSearch (searchString); if (query != null) { try { DetachQuery (); } catch (ObjectDisposedException e) {} } query = new Query (); query.AddDomain (QueryDomain.Neighborhood); // FIXME: Disable non-local searching for now. //query.AddDomain (QueryDomain.Global); query.AddText (searchString); root.SetSource (hit_type); AttachQuery (); root.Query = query; root.Start (); StartQuery (); UpdatePage (); }