Пример #1
0
        public bool RenameFolderIndexes(string oldFolderPath, string nowFolderPath, CancellationToken cancellationToken)
        {
            try
            {
                var documents = CodeIndexPool.Search(new PrefixQuery(GetNoneTokenizeFieldTerm(nameof(CodeSource.FilePath), oldFolderPath)), int.MaxValue);

                foreach (var document in documents)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    RenameIndex(document, oldFolderPath, nowFolderPath);
                }

                Log.LogInformation($"{Name}: Rename folder index from {oldFolderPath} to {nowFolderPath} successful, documents count: {documents.Length}");
                return(true);
            }
            catch (Exception ex)
            {
                Log.LogError($"{Name}: Rename folder index from {oldFolderPath} to {nowFolderPath} failed, exception: " + ex);
                return(false);
            }
        }
Пример #2
0
        public IndexBuildResults RenameFileIndex(string oldFilePath, string nowFilePath)
        {
            try
            {
                var documents = CodeIndexPool.Search(new TermQuery(GetNoneTokenizeFieldTerm(nameof(CodeSource.FilePath), oldFilePath)), 1);

                if (documents.Length == 1)
                {
                    RenameIndex(documents[0], oldFilePath, nowFilePath);

                    Log.LogInformation($"{Name}: Rename file index from {oldFilePath} to {nowFilePath} successful");

                    return(IndexBuildResults.Successful);
                }

                if (documents.Length == 0)
                {
                    Log.LogInformation($"{Name}: Rename file index failed, unable to find any document from {oldFilePath}, possible template file renamed, fallback to create index.");
                    return(CreateIndex(new FileInfo(nowFilePath)));
                }

                Log.LogWarning($"{Name}: Rename file index from {oldFilePath} to {nowFilePath} failed, unable to find one document, there are {documents.Length} document(s) founded");
                return(IndexBuildResults.FailedWithError);
            }
            catch (Exception ex)
            {
                Log.LogError($"{Name}: Rename file index from {oldFilePath} to {nowFilePath} failed, exception: " + ex);

                if (ex is IOException)
                {
                    return(IndexBuildResults.FailedWithIOException);
                }

                return(IndexBuildResults.FailedWithError);
            }
        }