Ejemplo n.º 1
0
 public HitSnippet[] GetSnippets(GetSnippetsRequest req)
 {
     object[] results = this.Invoke("GetSnippets", new object[] {
         req
     });
     return((HitSnippet[])(results[0]));
 }
Ejemplo n.º 2
0
		private bool tenHits = false;		//Flag to do Prefetch check only every 10 hits
		
		private void PrefetchSnippetsForNetworkHits(BT.TileHitCollection thc) 
		{		
			int lastDisplayed = 0;
			
			if (maxDisplayed != 0)
				lastDisplayed = thc.LastDisplayed + 1;
			
			//We have cached snippets for network hits upto maxDisplayed
			if (lastDisplayed < maxDisplayed)	
				return;

			maxDisplayed = thc.LastDisplayed + 1;
			
			//Do Prefetch check once every ten hits
			tenHits = !tenHits;
			if (!tenHits)					
				return; 
				
			if (lastDisplayed < thc.NumResults) {
			
				int limit = 0;
				ArrayList networkHits = new ArrayList();				
				
				if ((thc.NumResults - lastDisplayed) > MAX_HITS_AHEAD)
					limit = lastDisplayed + MAX_HITS_AHEAD;
				else
					limit = thc.NumResults;

				ArrayList hits = _rp.hitsCopy;
				lock (hits.SyncRoot) {
				
					if (limit > hits.Count)
						limit = hits.Count;

					log.Debug("PrefetchSnippets: Scanning result set for Network Hits from {0} to {1}", lastDisplayed, limit); 					
							
					//Get all NetworkHits with snippets field not initialized:
					for (int si = lastDisplayed;  si < limit ; si++)
					{
						if ((hits[si] is NetworkHit) && (((NetworkHit)hits[si]).snippet == null)) 
							networkHits.Add((NetworkHit)hits[si]);
					}
				}

				log.Debug("PrefetchSnippets: Found {0} NetworkHits without snippets", networkHits.Count);
				 
				while (networkHits.Count > 0) {
				
					ArrayList nwHitsPerNode = new ArrayList();
					string hostnamePort = GetHostnamePort((NetworkHit)networkHits[0]);
					
					//Gather NetworkHits from a specific target Networked Beagle
					foreach	(NetworkHit nh in networkHits) 
					{
						string hnp = GetHostnamePort(nh);
						if (hnp == null)
							continue;
							
						if (hnp.Equals(hostnamePort)) {

							if (nwHitsPerNode.Count < MAX_HIT_IDS_PER_REQ)
								nwHitsPerNode.Add(nh);
							else
								break;
						}
					}
											
					//Remove NetworkHits for this Networked Beagle	
					int i = networkHits.Count;
					while (--i >= 0) { 

						string hnp = GetHostnamePort((NetworkHit)networkHits[i]);							
						if ((hnp == null) || hnp.Equals(hostnamePort))
							networkHits.RemoveAt(i);
					}
			
					if (nwHitsPerNode.Count > 0)
					{
						string[] f3 = hostnamePort.Split(':');
						if (f3.Length < 2)
						{
							log.Warn("PrefetchSnippets: Invalid format netBeagle URI in NetworkHit");
							continue; 
						}
						BeagleWebService wsp = new BeagleWebService(f3[0], f3[1]);
							
						string searchToken = GetSearchToken((NetworkHit)nwHitsPerNode[0]);
						
						if (searchToken.Equals("beagle"))  //Check if it is Older version of Beagle networking
							searchToken = null;
							 			
						if (searchToken != null) {
						
							int[] hitHashCodes = new int [nwHitsPerNode.Count];
							for (int j = 0; j < hitHashCodes.Length; j++)
								hitHashCodes[j] = ((NetContext) ((NetworkHit)nwHitsPerNode[j]).context).hashCode;
							
							log.Debug("PrefetchSnippets: Invoking GetSnippets on {0} for {1} hits", wsp.Hostname, nwHitsPerNode.Count);
					
							GetSnippetsRequest sreq = new GetSnippetsRequest();
							sreq.searchToken = searchToken;
							sreq.hitHashCodes = hitHashCodes;
											
							ReqContext2 rc = new ReqContext2(wsp, nwHitsPerNode, thc);
							wsp.BeginGetSnippets(sreq, PrefetchSnippetsResponseHandler, rc);
						}	
						
						//Signal change in TileHitCollection due to addition of snippets:
						//_rp.rootTile.HitCollection.ClearSources(null);										
					}
				} //end while								
			} //end if 
		} 
Ejemplo n.º 3
0
 public System.IAsyncResult BeginGetSnippets(GetSnippetsRequest req, System.AsyncCallback callback, object asyncState)
 {
     return(this.BeginInvoke("GetSnippets", new object[] {
         req
     }, callback, asyncState));
 }
Ejemplo n.º 4
0
 public System.IAsyncResult BeginGetSnippets(GetSnippetsRequest req, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("GetSnippets", new object[] {
         req}, callback, asyncState);
 }
Ejemplo n.º 5
0
 public HitSnippet[] GetSnippets(GetSnippetsRequest req) {
     object[] results = this.Invoke("GetSnippets", new object[] {
         req});
     return ((HitSnippet[])(results[0]));
 }
Ejemplo n.º 6
0
		public HitSnippet[] getSnippets(GetSnippetsRequest req)
		{	
			HitSnippet[] response;
			string searchToken = req.searchToken;
			int[] hitHashCodes = req.hitHashCodes;
			
			if (!sessionTable.ContainsKey(searchToken)) {
			
				response = new HitSnippet[0];
				Logger.Log.Warn("GetSnippets: Invalid Search Token received ");
				return response;
			}
									
			ArrayList results = ((SessionData)sessionTable[searchToken]).results;
			if ((results == null) || (results.Count == 0)) {

				response = new HitSnippet[0];
				Logger.Log.Warn("GetSnippets: Invalid Search Token received ");
				return response;
			}
			
			int i = 0; 		
			ArrayList hashCodeList = new ArrayList();
			hashCodeList.AddRange(hitHashCodes);
				
			response = new HitSnippet[hitHashCodes.Length];
			Logger.Log.Debug("GetSnippets invoked with {0} hitHashCodes", hitHashCodes.Length);

			Query query = ((SessionData)sessionTable[searchToken]).query;
			
			lock (results.SyncRoot)  {
			
				string snippet = null; 
				foreach (Hit h in results)  {
				
					int hashCode = h.GetHashCode();
					if (hashCodeList.Contains(hashCode)) {
					
							hashCodeList.Remove(hashCode);	

							//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);		
							
							//GetSnippets always invoked on Target Beagle Node where hits originate:
							if (snippet == null)
								snippet = "";
								
							HitSnippet hs = new HitSnippet();
							hs.hashCode = hashCode; 
							hs.snippet = snippet.Trim();
							response[i++] = hs;		
					
							if ((hashCodeList.Count == 0) || (i == hitHashCodes.Length))
								return response;
					}
				} //end foreach
			} //end lock
			
			foreach (int hashCode in hashCodeList) {
					HitSnippet hs = new HitSnippet();
					hs.hashCode = hashCode; 
					hs.snippet = InvalidHitSnippetError;
					response[i++] = hs;	

					if (i == hitHashCodes.Length)
							break;
			}		
			Logger.Log.Warn("GetSnippets invoked some invalid hitIds");
			
			return response;
		}