Пример #1
0
        private void execSearch()
        {
            string query = tbxSearch.Text;

            d.Index            index    = new d.Index(d.Helper.INDEX_PATH);
            d.VSSearcher       searcher = new d.VSSearcher(index);
            d.ResultDocument[] results  = searcher.Search(query);
            StringBuilder      sb       = new StringBuilder();

            if (results != null)
            {
                sb.AppendFormat("<p>Found <b>{0}</b> relevant documents / displaying top 20:</p><table cellpadding=5 cellspacing=0 border=1>", results.Length);
                sb.Append("<tr bgcolor=#f1f1f1><td><b>similarity</b></td><td><b>title</b></td></tr>");
                int max = Math.Min(20, results.Length);
                for (int i = 0; i < max; i++)
                {
                    sb.AppendFormat("<tr><td>{0}</td><td><a href='http://en.wikipedia.org/wiki/{1}'>{1}</a></td></tr>",
                                    results[i].Similarity, index.GetURL(results[i].DocId));
                }
                sb.Append("</table>");
            }
            else
            {
                sb.Append("<p>Found <b>0</b> results");
            }

            ltrSearchResults.Text = sb.ToString();
        }
Пример #2
0
        public void run()
        {
            Console.WriteLine("Index loading...");

            DateTime t1 = DateTime.Now;

            d.Index      index = new d.Index(indexPath);
            d.VSSearcher vs    = new d.VSSearcher(index);

            DateTime t2 = DateTime.Now;

            Console.WriteLine("Query: ");
            string query = Console.ReadLine();

            Console.WriteLine("Searching for " + query);

            d.ResultDocument[] results = vs.Search(query);

            DateTime t3 = DateTime.Now;

            TimeSpan diff1 = t2 - t1;
            TimeSpan diff2 = t3 - t2;

            Console.WriteLine("load index time: " + diff1.Seconds + "." + diff1.Milliseconds);
            Console.WriteLine("search time: " + diff2.Seconds + "." + diff2.Milliseconds);

            if (results != null)
            {
                Console.WriteLine(results.Length + " results:");
                int max = Math.Min(10, results.Length);
                for (int i = 0; i < max; i++)
                {
                    Console.WriteLine("\t" + results[i].DocId + " " + results[i].Similarity + " " + index.GetURL(results[i].DocId));
                }
            }
        }