예제 #1
0
        public static void Main()
        {
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Console(outputTemplate: "{Timestamp:HH:mm:ss.fff} {Level} {Message:l} {Exception}{NewLine}{Properties}{NewLine}", theme: AnsiConsoleTheme.Grayscale)
                         .MinimumLevel.Information()
                         .Enrich.FromLogContext()
                         .CreateLogger();

            var directoryPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            using (var reindexer = ReindexerFactory.Create())
            {
                reindexer.RegisterDirectory(Path.Combine(directoryPath, "Data"));
                reindexer.RegisterFile(Path.Combine(directoryPath, "Data", "Dracula.txt"));
                reindexer.RegisterFile(Path.Combine(directoryPath, "Grimms.txt"));

                while (true)
                {
                    var query        = Console.ReadLine();
                    var foundResults = reindexer.Search(query).ToList();
                    Console.WriteLine("Found {0} results for {1}", foundResults.Count, query);
                    foreach (var foundResult in foundResults)
                    {
                        Console.WriteLine("---> {0}", foundResult);
                    }
                }
            }
        }
예제 #2
0
        private static void CreateFilesAndDeleteOneByOne(int count, TimeBudget timeout)
        {
            var directoryPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));

            Directory.CreateDirectory(directoryPath);

            var ids = Enumerable.Range(0, count).Select(x => Guid.NewGuid().ToString("N")).ToList();

            using (var reindexer = ReindexerFactory.Create())
            {
                reindexer.RegisterDirectory(directoryPath);

                foreach (var id in ids)
                {
                    File.WriteAllText(Path.Combine(directoryPath, id), id);
                }

                Wait(() => reindexer.IndexedFiles == count, timeout);

                foreach (var id in ids)
                {
                    var foundFilenames = reindexer.Search(id)
                                         .Select(Path.GetFileName)
                                         .ToList();

                    if (foundFilenames.Count == 1 && foundFilenames[0] == id)
                    {
                        continue;
                    }

                    throw new Exception($"Unexpected result {string.Join(",", foundFilenames)} of searching {id}");
                }

                foreach (var id in ids)
                {
                    File.Delete(Path.Combine(directoryPath, id));
                }

                Wait(() => reindexer.IndexedFiles == 0, timeout);

                foreach (var id in ids)
                {
                    var foundFilenames = reindexer.Search(id)
                                         .Select(Path.GetFileName)
                                         .ToList();

                    if (foundFilenames.Count == 0)
                    {
                        continue;
                    }

                    throw new Exception($"Unexpected result {string.Join(",", foundFilenames)} of searching {id}");
                }
            }
        }