예제 #1
0
        public static void RunApplicaiton(IndexerConfig config)
        {
            ProgressBar progress = null;
            IIndexer    indexer;

            if (config.UseLucene)
            {
                indexer = new LuceneIndexer();
            }
            else
            {
                indexer = new ElasticIndexer();
            }

            var indexResult = indexer.IndexFiles(config, result =>
            {
                if (progress == null)
                {
                    progress = new ProgressBar(PbStyle.DoubleLine, result.TotalFile, 200);
                }

                progress.Refresh(result.ReadedFiles, result.ToString());
            });

            Console.WriteLine(indexResult);
        }
예제 #2
0
        public IndexResult IndexFiles(IndexerConfig config, IndexerCallback callback = null)
        {
            var totalWatch = new Stopwatch();
            var directory  = FSDirectory.Open(config.IndexPath);
            var analyzer   = new WhitespaceAnalyzer();
            var files      = TextExtractor.GetFilesFromFolder(
                config.FolderPath,
                config.Extensions,
                config.IsRecusive);
            var result = new IndexResult
            {
                TotalFile = files.Count
            };

            totalWatch.Start();
            foreach (var file in files)
            {
                result.CurrentFile = file.FullName;
                callback?.Invoke(result);

                using (var writer = new IndexWriter(directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED))
                {
                    var stopwatch = new Stopwatch();
                    var document  = new Document();
                    var txtInfo   = TextExtractor.ReadText(file.FullName);
                    var fields    = GetFields(txtInfo, config.Excludes);

                    foreach (var field in fields)
                    {
                        document.Add(field);
                    }

                    stopwatch.Start();

                    writer.AddDocument(document, analyzer);
                    writer.Optimize();

                    stopwatch.Stop();

                    result.Time        = stopwatch.Elapsed;
                    result.ReadedFiles = TextExtractor.ReadedFile;
                    result.Size        = txtInfo.FileSize;

                    callback?.Invoke(result);
                }
            }
            totalWatch.Stop();

            result.Time        = totalWatch.Elapsed;
            result.ReadedFiles = TextExtractor.ReadedFile;
            result.Size        = TextExtractor.TotalSize;

            return(result);
        }
예제 #3
0
        public IndexResult IndexFiles(IndexerConfig config, IndexerCallback callback = null)
        {
            var totalWatch = new Stopwatch();
            var settings   = new ConnectionSettings(new Uri(config.IndexPath)).DefaultIndex("text");
            var files      = TextExtractor.GetFilesFromFolder(
                config.FolderPath,
                config.Extensions,
                config.IsRecusive);
            var client = new ElasticClient(settings);
            var result = new IndexResult
            {
                TotalFile = files.Count
            };

            ConfigMapping(client);

            totalWatch.Start();
            foreach (var file in files)
            {
                result.CurrentFile = file.FullName;
                callback?.Invoke(result);

                var stopwatch = new Stopwatch();
                var txtInfo   = TextExtractor.ReadText(file.FullName);
                var request   = new IndexRequest <TextInfo>
                {
                    Document = txtInfo,
                    Refresh  = Elasticsearch.Net.Refresh.True
                };

                stopwatch.Start();
                client.Index(request);
                stopwatch.Stop();

                result.Time        = stopwatch.Elapsed;
                result.ReadedFiles = TextExtractor.ReadedFile;
                result.Size        = txtInfo.FileSize;

                callback?.Invoke(result);
            }
            totalWatch.Stop();

            result.Time        = totalWatch.Elapsed;
            result.ReadedFiles = TextExtractor.ReadedFile;
            result.Size        = TextExtractor.TotalSize;

            return(result);
        }