예제 #1
0
        private static void TestBitMapIndexAndValidateResults(TagServer tagServer, QueryInfo queryInfo,
                                                              CLR.HashSet <string> tagsToExclude     = null,
                                                              EwahCompressedBitArray exclusionBitMap = null)
        {
            var result = tagServer.ComparisionQueryBitMapIndex(queryInfo, exclusionBitMap, printLoggingMessages: true);
            var errors = tagServer.GetInvalidResults(result.Questions, queryInfo);

            if (errors.Any())
            {
                using (Utils.SetConsoleColour(ConsoleColor.Red))
                    Logger.Log("ERROR Running \"{0}\" Query, {1} (out of {2}) results were invalid",
                               queryInfo.Operator, errors.Count, result.Questions.Count);
                foreach (var qu in errors)
                {
                    Logger.Log("  {0,8}: {1}", qu.Id, String.Join(", ", qu.Tags));
                }
                Logger.Log();
            }

            if (tagsToExclude != null && exclusionBitMap != null)
            {
                var shouldHaveBeenExcluded = tagServer.GetShouldHaveBeenExcludedResults(result.Questions, queryInfo, tagsToExclude);
                if (shouldHaveBeenExcluded.Any())
                {
                    using (Utils.SetConsoleColour(ConsoleColor.Red))
                        Logger.Log("ERROR Running \"{0}\" Query, {1} (out of {2}) questions should have been excluded",
                                   queryInfo.Operator, shouldHaveBeenExcluded.Select(s => s.Item1.Id).Distinct().Count(), result.Questions.Count);
                    foreach (var error in shouldHaveBeenExcluded)
                    {
                        Logger.Log("  {0,8}: {1} -> {2}", error.Item1.Id, String.Join(", ", error.Item1.Tags), string.Join(", ", error.Item2));
                    }
                    Logger.Log();
                }
            }
        }
예제 #2
0
        private static void RunAndOrNotComparisionQueries(TagServer tagServer, string tag1, string tag2, int pageSize, QueryType queryTypeToTest,
                                                          CLR.HashSet <string> tagsToExclude = null, EwahCompressedBitArray exclusionBitMap = null)
        {
            using (Utils.SetConsoleColour(ConsoleColor.Green))
                Logger.LogStartupMessage("\nComparison queries:\n\t\"{0}\" has {1:N0} questions\n\t\"{2}\" has {3:N0} questions",
                                         tag1, tagServer.AllTags[tag1], tag2, tagServer.AllTags[tag2]);

            var queries    = new[] { "AND", "OR", "AND-NOT", "OR-NOT" };
            var skipCounts = new[] { 0, 100, 250, 500, 1000, 2000, 4000, 8000 };

            foreach (var query in queries)
            {
                Results.CreateNewFile(string.Format("Results-{0}{1}-{2}-{3}-{4}-{5}.csv",
                                                    (tagsToExclude != null && exclusionBitMap != null) ? "With-Exclusions-" : "",
                                                    DateTime.Now.ToString("yyyy-MM-dd @ HH-mm-ss"), tag1, query, tag2, queryTypeToTest));
                Results.AddHeaders("Skip Count",
                                   String.Format("Regular {0} {1} {2}", tag1, query, tag2),
                                   String.Format("LINQ {0} {1} {2}", tag1, query, tag2),
                                   String.Format("BitMap {0} {1} {2}", tag1, query, tag2),
                                   String.Format("Regular {0} {1} {2}", tag2, query, tag1),
                                   String.Format("LINQ {0} {1} {2}", tag2, query, tag1),
                                   String.Format("BitMap {0} {1} {2}", tag2, query, tag1));

                using (Utils.SetConsoleColour(ConsoleColor.Yellow))
                    Logger.LogStartupMessage("\n{0} Comparison queries: {1} {0} {2}\n", query, tag1, tag2);
                foreach (var skipCount in skipCounts)
                {
                    Results.AddData(skipCount.ToString());

                    // Run the query both ways round, i.e. "c# AND-NOT jquery" as well as "jquery AND-NOT c#")
                    foreach (var tagPair in new[] { Tuple.Create(tag1, tag2), Tuple.Create(tag2, tag1) })
                    {
                        var info = new QueryInfo
                        {
                            Type     = queryTypeToTest,
                            Tag      = tagPair.Item1,
                            OtherTag = tagPair.Item2,
                            Operator = query,
                            PageSize = pageSize,
                            Skip     = skipCount
                        };

                        Console.ForegroundColor = ConsoleColor.DarkGreen;
                        var resultRegular = tagServer.ComparisonQueryNoLINQ(info, tagsToExclude);
                        var resultLINQ    = tagServer.ComparisonQuery(info, tagsToExclude);

                        //using (Utils.SetConsoleColour(ConsoleColor.Gray));
                        //    Utils.CompareLists(resultRegular.Questions, "Regular", resultLINQ.Questions, "LINQ");

                        Console.ForegroundColor = ConsoleColor.Cyan;
                        var resultBitMap = tagServer.ComparisionQueryBitMapIndex(info, exclusionBitMap, printLoggingMessages: true);

                        var invalidResults = tagServer.GetInvalidResults(resultBitMap.Questions, info);
                        var shouldHaveBeenExcludedResults = tagServer.GetShouldHaveBeenExcludedResults(resultBitMap.Questions, info, tagsToExclude);
                        if (shouldHaveBeenExcludedResults.Count > 0)
                        {
                            using (Utils.SetConsoleColour(ConsoleColor.Red))
                                Logger.LogStartupMessage("ERROR: shouldHaveBeenExcludedResults contains {0} items", shouldHaveBeenExcludedResults.Count);
                        }

                        using (Utils.SetConsoleColour(ConsoleColor.Red))
                        {
                            // See the TODO comments in ComplexQueryProcessor.cs for an explanation of this issue
                            if (query == "OR" || query == "OR-NOT")
                            {
                                Logger.LogStartupMessage("It is EXPECTED that {0} queries won't match when comparing \"Regular\" v. \"BitMap\"", query);
                            }
                        }

                        //using (Utils.SetConsoleColour(ConsoleColor.Gray));
                        //    Utils.CompareLists(resultRegular.Questions, "Regular", resultBitMap.Questions, "BitMap");
                    }

                    Console.ResetColor();
                    Results.StartNewRow();
                }

                Results.CloseFile();
            }
        }