protected void RequestSnippet () { if (snippet != null) { EmitGotSnippet (); } else { SnippetRequest sreq = new SnippetRequest (query, hit); sreq.RegisterAsyncResponseHandler (typeof (SnippetResponse), SnippetResponseReceived); sreq.SendAsync (); } }
public ISnippetReader GetSnippet (string[] query_terms, Hit hit, bool full_text, int ctx_length, int snp_length) { string source = hit ["beagle:Source"]; hit ["beagle:Source"] = hit ["beagle:OrigSource"]; string network_node = hit ["beagle:NetworkNode"]; SnippetReader snippet_reader = null; // FIXME: Creating a snippet request, registering transports, all of this // doing everytime for hundreds of hits may become quite expensive. // In that case, pre generate one snippetrequest and use it over and over. // Form a correct snippet request SnippetRequest sreq = new SnippetRequest (); sreq.Hit = hit; sreq.QueryTerms = query_terms; sreq.FullText = full_text; sreq.ContextLength = ctx_length; sreq.SnippetLength = snp_length; // fake a blocking snippet retrieval sreq.RegisterAsyncResponseHandler (typeof (SnippetResponse), delegate (ResponseMessage response) { if (response is ErrorResponse) { Log.Error ("Error retrieval snippet for {0} from network node {1}", hit.Uri, network_node); return; } snippet_reader = new SnippetReader ((SnippetResponse) response); }); List<string[]> network_services = Conf.Networking.GetListOptionValues (Conf.Names.NetworkServices); foreach (string[] service in network_services) { if (network_node != service [0]) continue; sreq.Transports.Clear (); sreq.RegisterTransport (new HttpTransport (service [1])); // fake a blocking snippet retrieval try { sreq.SendAsyncBlocking (); } catch (Exception e) { Log.Debug (e, "Error while requesting snippet from {0} for {1}", service [1], hit.Uri); } break; } hit ["beagle:Source"] = source; // reset source return snippet_reader; }