当前位置: 首页>>代码示例>>C#>>正文


C# IndexSearcher.doc方法代码示例

本文整理汇总了C#中IndexSearcher.doc方法的典型用法代码示例。如果您正苦于以下问题:C# IndexSearcher.doc方法的具体用法?C# IndexSearcher.doc怎么用?C# IndexSearcher.doc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IndexSearcher的用法示例。


在下文中一共展示了IndexSearcher.doc方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Load

        private bool Load(IndexSearcher searcher)
        {
            var query = new BooleanQuery();
            query.add(new TermQuery(new Term(PreferencesDocumentField, PreferencesName)), BooleanClause.Occur.MUST);

            nextFolderId = 1;

            var results = searcher.search(query, 1);
            if (results.totalHits > 0)
            {
                var doc = searcher.doc(results.scoreDocs[0].doc);
                if (doc.get(RegisteredFoldersField) != null)
                {
                    var prefs = JsonConvert.DeserializeObject<FolderPreferences>(doc.get(RegisteredFoldersField));
                    nextFolderId = prefs.NextFolderId;
                    foreach (var fm in prefs.FolderMapping)
                        registeredFolders.Add(fm.Id, fm.Path);
                    return true;
                }
            }

            return false;
        }
开发者ID:kevintavog,项目名称:FindAPhoto-1.net,代码行数:23,代码来源:IndexPreferences.cs

示例2: IndexFolder

        public void IndexFolder(string folderName)
        {
            IDictionary<string,JToken> exifInfo = null;

            var didAddFiles = false;
            string[] allFilenames;
            try
            {
                allFilenames = System.IO.Directory.GetFiles(folderName);
            }
            catch (Exception ex)
            {
                logger.Error(String.Format("Exception getting filenames from {0}: {1}", folderName, ex));
                return;
            }

            foreach (var filename in allFilenames)
            {
                try
                {
                    if (mainReader.Value == null)
                    {
                        mainReader.Value = DirectoryReader.open(mainWriter.getDirectory());
                    }

                    CheckForCommit(mainWriter);

                    Interlocked.Increment(ref fileNumber);
                    if ((FileNumber % 100) == 0)
                    {
                        var seconds = (DateTime.Now - startTime).TotalSeconds;
                        logger.Debug("Processed {0} files in {1:N0} seconds ({2:N2} files/second); processing {3}", 
                            FileNumber,
                            seconds,
                            FileNumber / seconds,
                            filename);
                    }

                    if (!FileTypes.IsSupportedFilename(filename))
                        continue;

                    string hashValue = CalculateHash(filename);
                    var query = new BooleanQuery();
                    var fileInfo = new FileInfo(filename);

                    query.add(new TermQuery(new Term(FieldName.SignatureIndexPath, indexPreferences.ToIndexPath(filename))), BooleanClause.Occur.MUST);

                    var searcher = new IndexSearcher(mainReader.Value);
                    var results = searcher.search(query, 1);
                    if (results.totalHits > 0)
                    {
                        var existingDoc = searcher.doc(results.scoreDocs[0].doc);

                        // Skip this file? - no changes since it was last indexed
                        if (IsCurrent(existingDoc, filename, hashValue, fileInfo.Length))
                        {
                            // Ensure a thumbnail exists for this file
                            thumbnailIndexer.CheckThumbnail(
                                filename, 
                                existingDoc.get(FieldName.MimeType), 
                                existingDoc.get(FieldName.Size));

                            continue;
                        }

                        var deleteQuery = new BooleanQuery();
                        deleteQuery.add(new TermQuery(new Term(FieldName.SignatureIndexPath, indexPreferences.ToIndexPath(filename))), BooleanClause.Occur.MUST);
                        mainWriter.deleteDocuments(deleteQuery);
                    }

                    if (exifInfo == null)
                    {
                        try
                        {
                            exifInfo = BatchExifTool(folderName);
                        }
                        catch (Exception e)
                        {
                            logger.Warn("Skipping '{0}' due to exif failure: {1}", Path.GetDirectoryName(filename), e.Message);
                            break;
                        }
                    }

                    var exifSourceFile = filename;
                    foreach (var folderPrefix in Preferences.Instance.FoldersToWatch)
                        exifSourceFile = exifSourceFile.Replace(folderPrefix, "");

                    JToken exif;
                    exifInfo.TryGetValue(exifSourceFile.ToLower().Replace('\\', '/'), out exif);
                    var doc = new Document();

                    if (ProcessFile(filename, doc, hashValue, exif))
                    {
                        var facetsConfig = FindAPhoto.Common.Facets.FacetsConfig;
                        mainWriter.addDocument(facetsConfig.build(taxonomyWriter, doc));
                        ++FilesAdded;
                        didAddFiles = true;

                        MadeChange();
                    }
//.........这里部分代码省略.........
开发者ID:kevintavog,项目名称:FindAPhoto-1.net,代码行数:101,代码来源:DocumentIndexer.cs


注:本文中的IndexSearcher.doc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。