Exemplo n.º 1
0
    private static void OnHitsAdded(HitsAddedResponse response)
    {
        lastQueryTime = DateTime.Now;

        if (count == 0 && verbose)
        {
            Console.WriteLine("First hit returned in {0:0.000}s",
                              (lastQueryTime - queryStartTime).TotalSeconds);
        }

        if (verbose)
        {
            if (response.NumMatches >= 0)
            {
                Console.WriteLine("Returned latest {0} results out of total {1} matches", response.Hits.Count, response.NumMatches);
            }
            else
            {
                Console.WriteLine("Returned latest {0} results", response.Hits.Count);
            }
        }

        if (!display_hits)
        {
            count += response.Hits.Count;
            return;
        }

        foreach (Hit hit in response.Hits)
        {
            string uri = (raw_uri ?  hit.Uri.OriginalString : UriFu.EscapedUriToString(hit.Uri));
            if (verbose)
            {
                Console.WriteLine("  Uri: {0}", uri);
            }
            else
            {
                Console.WriteLine(uri);
            }

            if (verbose)
            {
                SnippetRequest sreq = new SnippetRequest(query, hit);
                if (display_cached_text)
                {
                    sreq.FullText = true;
                }

                SnippetResponse sresp = (SnippetResponse)sreq.Send();
                Console.WriteLine("PaUri: {0}", hit.ParentUri != null ? hit.ParentUri.ToString() : "(null)");
                if (!display_cached_text)
                {
                    Console.WriteLine(" Snip: {0}", sresp.Snippet != null ? sresp.Snippet : "(null)");
                }
                Console.WriteLine(" Type: {0}", hit.Type);
                Console.WriteLine("MimeT: {0}", hit.MimeType == null ? "(null)" : hit.MimeType);
                Console.WriteLine("  Src: {0}", hit.Source);
                Console.WriteLine("Score: {0}", hit.Score);
                if (hit.ValidTimestamp)
                {
                    Console.WriteLine(" Time: {0}", DateTimeUtil.ToString(hit.Timestamp));
                }

                foreach (Property prop in hit.Properties)
                {
                    Console.WriteLine("    {0} = '{1}'",
                                      prop.Key,
                                      (prop.Type != PropertyType.Date ? prop.Value : DateTimeUtil.ToString(StringFu.StringToDateTime(prop.Value))));
                }


                if (display_cached_text)
                {
                    Console.WriteLine("-- Cache -------------------------------------");
                    if (sresp.SnippetList.Snippets == null)
                    {
                        Console.WriteLine("(empty)");
                    }
                    else
                    {
                        foreach (SnippetLine snippet_line in sresp.SnippetList.Snippets)
                        {
                            if (snippet_line == null || snippet_line.Fragments == null)
                            {
                                Console.WriteLine("(empty)");
                            }
                            else
                            {
                                Console.WriteLine(((Fragment)snippet_line.Fragments [0]).Text);
                            }
                        }
                    }
                    Console.WriteLine("----------------------------------------------");
                }
                Console.WriteLine();
            }

            ++count;
        }
    }