Exemplo n.º 1
0
		private void DisconnectResult ()
		{
			if (this.result == null)
				return;

			this.result.HitsAddedEvent -= OnResultHitsAdded;
			this.result.HitsSubtractedEvent -= OnResultHitsSubtracted;
			this.result.FinishedEvent -= OnResultFinished;
					
			this.result.Cancel ();
			this.result.Dispose ();
			this.result = null;
		}
Exemplo n.º 2
0
		void DetachQueryResult (QueryResult qres)
		{
			if (qres != null) {

				if (resultTable.Contains(qres)) {
					SessionData sdata = ((SessionData) resultTable[qres]);	
					sdata.results.Sort();
				}
				qres.HitsAddedEvent -= OnHitsAdded;
				qres.HitsSubtractedEvent -= OnHitsSubtracted;
				qres.FinishedEvent -= OnFinished;
				qres.CancelledEvent -= OnCancelled;

				resultTable.Remove(qres);
				qres.Dispose ();
			}
		}
Exemplo n.º 3
0
		void AttachQueryResult (QueryResult qres, SessionData sdata)
		{
			if (qres != null) {

				qres.HitsAddedEvent += OnHitsAdded;
				qres.HitsSubtractedEvent += OnHitsSubtracted;
				qres.FinishedEvent += OnFinished;
				qres.CancelledEvent += OnCancelled;

				resultTable.Add(qres, sdata);
			}
		}
Exemplo n.º 4
0
		void OnFinished (QueryResult qres)
		{
			DetachQueryResult (qres);
		}
Exemplo n.º 5
0
		public void OnResultHitsAdded (QueryResult result, ICollection some_hits, int total_results)
		{
			HitsAddedResponse response = new HitsAddedResponse (some_hits, total_results);

			this.SendAsyncResponse (response);
		}
Exemplo n.º 6
0
		private void DetachQueryResult (QueryResult qres)
		{
			if (qres != null) {
			
				if (result.Contains(qres))
				{
					Resp resp = ((Resp) result[qres]);
					ArrayList hitsCopy = resp.resultPair.hitsCopy;
					if (hitsCopy != null)
						hitsCopy.Sort();
					
					resp.bufferContext.maxDisplayed = 0;
					
					result.Remove(qres);
				}
							
				qres.HitsAddedEvent -= OnHitsAdded;
				qres.HitsSubtractedEvent -= OnHitsSubtracted;
				qres.FinishedEvent -= OnFinished;
				qres.CancelledEvent -= OnCancelled;

				qres.Dispose ();
			}
		}
Exemplo n.º 7
0
		void OnCancelled (QueryResult qres)
		{
			DetachQueryResult(qres);			
		}
Exemplo n.º 8
0
		void OnHitsSubtracted (QueryResult qres, ICollection uris)
		{
			if (result.Contains(qres)) {
				BT.SimpleRootTile root = ((Resp) result[qres]).resultPair.rootTile;
				lock (root) {
					root.Subtract (uris);
					removeUris(((Resp) result[qres]).resultPair.hitsCopy, uris);
				}
			}
		}
Exemplo n.º 9
0
		static private void QueryEachQueryable (Query query, QueryResult result)
		{
			// The extra pair of calls to WorkerStart/WorkerFinished ensures:
			// (1) that the QueryResult will fire the StartedEvent
			// and FinishedEvent, even if no queryable accepts the
			// query.
			// (2) that the FinishedEvent will only get called when all of the
			// backends have had time to finish.

			object dummy_worker = new object ();

			if (! result.WorkerStart (dummy_worker))
				return;

			try {
				iqueryable_lock.AcquireReaderLock (System.Threading.Timeout.Infinite);

				foreach (Queryable queryable in Queryables)
					DoOneQuery (queryable, query, result, null);
			} finally {
				iqueryable_lock.ReleaseReaderLock ();
			}
			
			result.WorkerFinished (dummy_worker);
		}
Exemplo n.º 10
0
		static public void DoOneQuery (Queryable            queryable,
					       Query                query,
					       QueryResult          result,
					       IQueryableChangeData change_data)
		{
			try {
				if (queryable.AcceptQuery (query)) {
					QueryClosure qc = new QueryClosure (queryable, query, result, change_data);
					result.AttachWorker (qc);
				}
			} catch (Exception ex) {
				Logger.Log.Warn (ex, "Caught exception calling DoOneQuery on '{0}'", queryable.Name);
			}
		}
Exemplo n.º 11
0
			public QueryClosure (Queryable            queryable,
					     Query                query,
					     QueryResult          result,
					     IQueryableChangeData change_data)
			{
				this.queryable = queryable;
				this.query = query;
				this.result = result;
				this.change_data = change_data;
			}
Exemplo n.º 12
0
			public QueryWorkerClosure (IQueryWorker _worker, QueryResult _result)
			{
				worker = _worker;
				result = _result;
			}
Exemplo n.º 13
0
		public override ResponseMessage Execute (RequestMessage req)
		{
			this.query = (Query) req;

			this.result = new QueryResult ();
			this.result.IsIndexListener = this.query.IsIndexListener;
			AttachResult ();

			QueryDriver.ChangedEvent += OnQueryDriverChanged;
			QueryDriver.DoQuery (query,
					     this.result,
					     new RequestMessageExecutor.AsyncResponse (this.SendAsyncResponse));

			// Don't send a response; we'll be sending them async
			return null;
		}
Exemplo n.º 14
0
		public void OnResultFinished (QueryResult result)
		{
			this.SendAsyncResponse (new FinishedResponse ());
		}
Exemplo n.º 15
0
		public void OnResultHitsSubtracted (QueryResult result, ICollection some_uris)
		{
			HitsSubtractedResponse response = new HitsSubtractedResponse (some_uris);

			this.SendAsyncResponse (response);
		}
Exemplo n.º 16
0
		//Full beagledQuery
		public SearchResult doQuery(SearchRequest sreq, bool isLocalReq)
		{	
			SearchResult sr = null;

			if (sreq.text == null || sreq.text.Length == 0 ||
				(sreq.text.Length == 1 && sreq.text[0].Trim() == "") ) {
				
			    sr = new SearchResult();
			    sr.statusCode = SC_INVALID_QUERY;
			    sr.statusMsg = "Error: No search terms specified";
				return sr;
			}

			Query query = new Query();

			string searchString = "";						
			foreach (string text in sreq.text)  {
				query.AddText(text);
				searchString += (searchString.Length == 0) ? text:" " + text;
			}			
			
			Logger.Log.Info("WebServiceBackEnd: Received {0} WebService Query with search term: {1}", isLocalReq ? "Local":"External", searchString.Trim());

			if (sreq.mimeType != null && sreq.mimeType[0] != null)
				foreach (string mtype in sreq.mimeType)
					query.AddMimeType(mtype);

			if (sreq.searchSources != null && sreq.searchSources[0] != null)
				foreach (string src in sreq.searchSources)
					query.AddSource(src);

			//If needed, check to restrict queries to System or Neighborhood domain, can be added here
			if (sreq.qdomain > 0)
				query.AddDomain(sreq.qdomain);
						
			if (!isLocalReq) {	//External Request, check if this Node is already processing it

			 	lock (this) {					
					if ((sreq.searchId != 0) && NetworkedBeagle.IsCachedRequest(sreq.searchId)) {

						sr = new SearchResult();
				    	sr.numResults = sr.totalResults = sr.firstResultIndex = 0;
						sr.hitResults = new HitResult[sr.numResults];	
				 		sr.searchToken = "";

				 		sr.statusCode = SC_DUPLICATE_QUERY;
				 		sr.statusMsg = "Error: Duplicate Query loopback";
				 		Logger.Log.Warn("WebServiceBackEnd: Received duplicate Query for a query already in process!");
				 		Logger.Log.Warn("WebServiceBackEnd: Check NetBeagle configuration on all nodes to remove possible loops");
				 	}
	
					if (sreq.hopCount >= 5)  {
						//If request has traversed 5 nodes in reaching here, stop cascading. 
						//Make it a Local Query.
						query.RemoveDomain(sreq.qdomain);
						query.AddDomain(QueryDomain.System);
				 	}
				 					 	
					if ((sr == null) && (sreq.searchId != 0) )
						NetworkedBeagle.CacheRequest(query, sreq.searchId, sreq.hopCount + 1);				 	
				 }
				 
				 if (sr != null)
				 	return sr;	
				 	
				 //Logger.Log.Info("New external Query: searchId = {0}", sreq.searchId); 	
			}

			ArrayList results = ArrayList.Synchronized(new ArrayList());
			
			QueryResult qres = new QueryResult ();

			string searchToken = TokenGenerator();
						
			SessionData sdata = new SessionData(query, results, isLocalReq);
				
			AttachQueryResult (qres, sdata);
			
/* Include this code, if sessionID passed from front-end:
			if (sessionTable.Contains(searchToken))
				sessionTable[searchToken] = sdata;
			else
*/
			sessionTable.Add(searchToken, sdata);
			
			QueryDriver.DoQueryLocal (query, qres);
					
			while (resultTable.Contains(qres) && (results.Count < MAX_RESULTS_PER_CALL) )
				Thread.Sleep(100);

			//Console.WriteLine("WebServiceBackEnd: Got {0} results from beagled", results.Count);
			sr = new SearchResult();

			if (results.Count > 0)
			{ 
			  lock (results.SyncRoot) { //Lock results ArrayList to prevent more Hits added till we've processed doQuery
			
				sr.numResults = results.Count < MAX_RESULTS_PER_CALL ? results.Count: MAX_RESULTS_PER_CALL;	
				sr.hitResults = new HitResult[sr.numResults];
			    
			    string hitUri;			
				for (int i = 0; i < sr.numResults; i++) {
				
					Hit h = (Hit) results[i];

					string snippet; 
						
					//Queryable queryable = h.SourceObject as Queryable;
					Queryable queryable = QueryDriver.GetQueryable (h.SourceObjectName);
					
					if (queryable == null)
						snippet = "ERROR: hit.SourceObject is null, uri=" + h.Uri;
					else
						snippet = queryable.GetSnippet (ICollection2StringList(query.StemmedText), h);											
								
					sr.hitResults[i] = new HitResult();
					
					hitUri = h.UriAsString;
					if (isLocalReq || hitUri.StartsWith(NetworkedBeagle.BeagleNetPrefix))
							sr.hitResults[i].uri = hitUri;
					else
							sr.hitResults[i].uri = AccessFilter.TranslateHit(h);
					
	        	    sr.hitResults[i].resourceType = h.Type;
					sr.hitResults[i].mimeType = h.MimeType;
					sr.hitResults[i].source = h.Source;
					sr.hitResults[i].score = h.Score;				
				
					int plen = h.Properties.Count;
					sr.hitResults[i].properties = new HitProperty[plen];
					for (int j = 0; j < plen; j++) {
						Property p = (Property) h.Properties[j];
						sr.hitResults[i].properties[j] = new HitProperty();
						sr.hitResults[i].properties[j].PKey = p.Key;
						sr.hitResults[i].properties[j].PVal = p.Value;				
						sr.hitResults[i].properties[j].IsMutable = p.IsMutable;				
						sr.hitResults[i].properties[j].IsSearched = p.IsSearched;							
					}

					sr.hitResults[i].hashCode = h.GetHashCode ();
					
					if (snippet != null)
						sr.hitResults[i].snippet = snippet.Trim();
				}					
			   } //end lock
			 }// end if
			 else {

			    sr.numResults = 0;
				sr.hitResults = new HitResult[sr.numResults];	
			 }

			 sr.totalResults = results.Count;
			 
			 sr.firstResultIndex = 0;			 
			 sr.searchToken = "";
				
			 if (sr.totalResults > 0)
				sr.searchToken = searchToken;
					
			 sr.statusCode = SC_QUERY_SUCCESS;
			 sr.statusMsg = "Success";
			 Logger.Log.Info("WebServiceBackEnd: Total Results = "  + sr.totalResults);			
			 return sr;
		}
Exemplo n.º 17
0
		void OnHitsAdded (QueryResult qres, ICollection hits)
		{	
			if (result.Contains(qres)) {
			
				Resp resp = ((Resp) result[qres]);
				BT.SimpleRootTile root = resp.resultPair.rootTile;
				ArrayList hitsCopy = resp.resultPair.hitsCopy;
				
				lock (root)  {
					if (resp.isLocalReq) {
						root.Add(hits);
						lock (hitsCopy.SyncRoot)
							hitsCopy.AddRange(hits);
					}
					else {
							foreach (Hit h in hits)							
							   if (h.UriAsString.StartsWith(NetworkedBeagle.BeagleNetPrefix) ||
							 	 			WebServiceBackEnd.AccessFilter.FilterHit(h)) {
									root.Add(h);
									lock (hitsCopy.SyncRoot)
										hitsCopy.Add(h);
								}
					}
				}
			}
		}
Exemplo n.º 18
0
		static public void DoQueryLocal (Query       query,
						 QueryResult result)
		{
			DehumanizeQuery (query);

			SearchTermResponse search_term_response;
			search_term_response = AssembleSearchTermResponse (query);
			query.ProcessSearchTermResponse (search_term_response);

			QueryEachQueryable (query, result);
		}
Exemplo n.º 19
0
		void OnFinished (QueryResult qres)
		{
			if (result.Contains(qres))
				log.Info("WebBackEnd:OnFinished() - Got {0} results from beagled QueryDriver", ((Resp) result[qres]).resultPair.rootTile.HitCollection.NumResults);

			DetachQueryResult(qres);
		}
Exemplo n.º 20
0
		static public void DoQuery (Query                                query,
					    QueryResult                          result,
					    RequestMessageExecutor.AsyncResponse send_response)
		{
			DehumanizeQuery (query);

			SearchTermResponse search_term_response;
			search_term_response = AssembleSearchTermResponse (query);
			send_response (search_term_response);

			QueryEachQueryable (query, result);
		}
Exemplo n.º 21
0
		private void AttachQueryResult (QueryResult qres, Resp resp)
		{
			if (qres != null) {
			
				qres.HitsAddedEvent += OnHitsAdded;
				qres.HitsSubtractedEvent += OnHitsSubtracted;
				qres.FinishedEvent += OnFinished;
				qres.CancelledEvent += OnCancelled;

				result.Add(qres, resp);
			}
		}
Exemplo n.º 22
0
		void OnHitsAdded (QueryResult qres, ICollection hits)
		{
			if (resultTable.Contains(qres)) {
			
				SessionData sdata = ((SessionData) resultTable[qres]);	
				ArrayList results = sdata.results;
				bool localReq = sdata.localRequest;
			
				if (localReq){
					lock (results.SyncRoot) 
						results.AddRange(hits);
				}
				else {				
						//Query query = sdata.query;					
					lock (results.SyncRoot) {
						foreach (Hit h in hits) 
							if (h.UriAsString.StartsWith(NetworkedBeagle.BeagleNetPrefix) ||
											AccessFilter.FilterHit(h))
								results.Add(h);
					}
				}
			}
		}
Exemplo n.º 23
0
		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));
			}			
		}
Exemplo n.º 24
0
		void OnHitsSubtracted (QueryResult qres, ICollection uris)
		{
			if (resultTable.Contains(qres)) {
				SessionData sdata = ((SessionData) resultTable[qres]);	
				ArrayList results = sdata.results;
				removeUris(results, uris);
			}
		}