Compute lucene-style scores for our hits.
[beagle.git] / bludgeon / SanityCheck.cs
blob1f3188d49e6e8821073354d28799329d8e8a9108
2 using System;
3 using System.Collections;
5 using Beagle.Util;
7 namespace Bludgeon {
9 public class SanityCheck {
11 private SanityCheck () { }
13 static public bool CheckQuery (Beagle.Query query, FileModel root)
15 Hashtable matching_path_hash;
16 matching_path_hash = new Hashtable ();
18 foreach (Uri uri in QueryFu.GetUris (query))
19 matching_path_hash [uri.LocalPath] = null;
21 bool success;
22 success = true;
24 foreach (FileModel file in root.GetMatchingDescendants (query)) {
25 if (! matching_path_hash.Contains (file.FullName)) {
26 Log.Failure ("Missing match {0}", file.FullName);
27 success = false;
29 matching_path_hash.Remove (file.FullName);
32 foreach (string path in matching_path_hash.Keys) {
33 Log.Failure ("Unexpected match {0}", path);
34 success = false;
37 return success;
40 static public bool VerifyIndex (FileModel root)
42 Log.Info ("Verifying index for {0}", root.FullName);
44 bool success;
45 success = true;
47 for (int i = 0; i < Token.Count; ++i) {
48 Beagle.Query query;
49 query = QueryFu.NewTokenQuery (i);
51 if (! CheckQuery (query, root)) {
52 Log.Spew ("Failed query is:");
53 QueryFu.SpewQuery (query);
54 success = false;
58 if (success)
59 Log.Info ("Index successfully verified for {0}", root.FullName);
60 else
61 Log.Info ("Verification failed for {0}", root.FullName);
63 return success;
66 static public bool TestRandomQueries (FileModel root,
67 double minutes_to_run)
69 Log.Info ("Running random queries on {0} for {1:0.0} minutes", root.FullName, minutes_to_run);
71 bool success;
72 success = true;
74 Stopwatch sw;
75 sw = new Stopwatch ();
76 sw.Start ();
78 int count = 0;
79 while (true) {
80 if ((count % 100 == 0) && sw.ElapsedTime > minutes_to_run * 60)
81 break;
82 ++count;
84 Beagle.Query query;
85 query = QueryFu.NewRandomQuery ();
87 if (! CheckQuery (query, root)) {
88 Log.Spew ("Failed query is:");
89 QueryFu.SpewQuery (query);
90 success = false;
91 break;
95 // In case we ended early
96 minutes_to_run = sw.ElapsedTime / 60;
98 Log.Spew ("Ran {0} queries in {1:0.0} minutes ({2:0.0} queries/s)",
99 count, minutes_to_run, count / (minutes_to_run * 60));
101 return success;