示例#1
0
        public Searcher(string mainFolder, string taxonomyFolder, string thumbsFolder)
        {
            MaxResultCount = 50;
            mainSearchManager = new SearchManager(FSDirectory.open(new java.io.File(mainFolder)));
            taxonomyReader = new DirectoryTaxonomyReader(FSDirectory.open(new java.io.File(taxonomyFolder)));

            analyzer = FindAPhotoAnalyzers.ForSearching();
            parser = new MultiFieldQueryParser(FieldName.DefaultSearchFields, analyzer);
            parser.setAllowLeadingWildcard(true);

            thumbSearchManager = new SearchManager(FSDirectory.open(new java.io.File(thumbsFolder)));

            using (var wrapper = mainSearchManager.Wrapper())
            {
                indexPreferences = new IndexPreferences(wrapper.IndexSearcher);
            }
        }
        public ThumbnailIndexer(IndexPreferences indexPreferences)
        {
            this.indexPreferences = indexPreferences;

            if (!System.IO.Directory.Exists(Preferences.Instance.ThumbIndexFolder))
            {
                logger.Info("Creating thumbs folder: '{0}'", Preferences.Instance.ThumbIndexFolder);
                System.IO.Directory.CreateDirectory(Preferences.Instance.ThumbIndexFolder);
            }

            var config = new IndexWriterConfig(FindAPhotoAnalyzers.IndexVersion, FindAPhotoAnalyzers.ForIndexing());
            writer = new IndexWriter(
                FSDirectory.open(new java.io.File(Preferences.Instance.ThumbIndexFolder)),
                config);
            writer.commit();

            searchManager = new SearchManager(writer.getDirectory());

            tasks.Add(Task.Run(DequeueFiles));
            tasks.Add(Task.Run(DequeueFiles));
            tasks.Add(Task.Run(CommitTask));
        }
        private void VisitAllDocuments(IndexWriter writer, Action<IndexWriter,Document> action)
        {
            using (var searchManager = new SearchManager(writer.getDirectory()))
            {
                using (var search = searchManager.Wrapper())
                {
                    var results = search.IndexSearcher.search(new MatchAllDocsQuery(), writer.maxDoc());
                    for (int idx = 0; idx < results.totalHits; ++idx)
                    {
                        if (shutdown)
                        {
                            break;
                        }

                        CheckForCommit(writer);
                        action(writer, search.IndexSearcher.doc(results.scoreDocs[idx].doc));
                    }
                }
            }
        }