Ejemplo n.º 1
0
        public void Search_Result_Is_Same_For_InvertedIndex_And_SimpleSearching()
        {
            var tokenizer = new DefaultTokenizer();
            var ticks     = Environment.TickCount;

            Console.WriteLine($"Test ticks: {ticks}");
            var lines         = TestDataGenerator.GetRandomLines(ticks);
            var invertedIndex = new InvertedIndex(tokenizer);
            var phrase        = TestDataGenerator.GetSearchPhrase(ticks);

            BuildIndex(invertedIndex, lines);

            var inmemoryResult = InmemorySimpleSearch.Find(lines, phrase);

            invertedIndex.Find(phrase)
            .Select(x => new { x.RowNumber, x.ColNumber })
            .Should()
            .BeEquivalentTo(inmemoryResult.Select(x => new { x.RowNumber, x.ColNumber }));
        }
Ejemplo n.º 2
0
        public void InvertedIndex_Should_Be_Faster_Than_Simple_Searching()
        {
            const int phrasesCount = 50;
            var       phrases      = new string[phrasesCount];
            var       tickCount    = Environment.TickCount;

            Console.WriteLine($"TickCount: {tickCount}");
            for (var i = 0; i < phrasesCount; i++)
            {
                phrases[i] = TestDataGenerator.GetSearchPhrase(tickCount + i);
            }

            var tokenizer     = new DefaultTokenizer();
            var stopWatch     = new Stopwatch();
            var lines         = TestDataGenerator.GetRandomLines(tickCount, 50000);
            var invertedIndex = new InvertedIndex(tokenizer);

            BuildIndex(invertedIndex, lines);

            stopWatch.Start();
            for (var i = 0; i < phrasesCount; i++)
            {
                var elapsedBefore = stopWatch.Elapsed;
                invertedIndex.Find(phrases[i]);
                var elapsed = stopWatch.Elapsed - elapsedBefore;
                Console.WriteLine($"Elapsed for phrase: {phrases[i]} {elapsed}");
            }

            var indexSearchingTime = stopWatch.Elapsed;

            stopWatch.Restart();
            for (var i = 0; i < phrasesCount; i++)
            {
                InmemorySimpleSearch.Find(lines, phrases[i]);
            }

            var simpleSearchingTime = stopWatch.Elapsed;

            Console.WriteLine($"InvertedIndex searching time: {indexSearchingTime}");
            Console.WriteLine($"Simple searching time: {simpleSearchingTime}");
            indexSearchingTime.Should().BeLessThan(simpleSearchingTime);
        }