mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
do not scan all files when trigram index is available
This commit is contained in:
@@ -238,6 +238,8 @@ class FindInProjectTask {
|
||||
@Override
|
||||
public boolean processFile(@NotNull final VirtualFile virtualFile) {
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
final boolean hasTrigrams = hasTrigrams(myFindModel.getStringToFind());
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ProgressManager.checkCanceled();
|
||||
@@ -247,7 +249,7 @@ class FindInProjectTask {
|
||||
return;
|
||||
}
|
||||
|
||||
if (skipIndexed && isCoveredByIdIndex(virtualFile) &&
|
||||
if (skipIndexed && isCoveredByIndex(virtualFile) &&
|
||||
(fileIndex.isInContent(virtualFile) || fileIndex.isInLibraryClasses(virtualFile) || fileIndex.isInLibrarySource(virtualFile))) {
|
||||
return;
|
||||
}
|
||||
@@ -259,6 +261,16 @@ class FindInProjectTask {
|
||||
myFiles.add(psiFile);
|
||||
}
|
||||
}
|
||||
|
||||
final FileBasedIndexImpl fileBasedIndex = (FileBasedIndexImpl)FileBasedIndex.getInstance();
|
||||
|
||||
private boolean isCoveredByIndex(VirtualFile file) {
|
||||
FileType fileType = file.getFileType();
|
||||
if (hasTrigrams) {
|
||||
return TrigramIndex.isIndexable(fileType) && fileBasedIndex.isIndexingCandidate(file, TrigramIndex.INDEX_ID);
|
||||
}
|
||||
return IdIndex.isIndexable(fileType) && fileBasedIndex.isIndexingCandidate(file, IdIndex.NAME);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
@@ -304,12 +316,6 @@ class FindInProjectTask {
|
||||
return iterator.getFiles();
|
||||
}
|
||||
|
||||
private static boolean isCoveredByIdIndex(VirtualFile file) {
|
||||
FileBasedIndexImpl fileBasedIndex = (FileBasedIndexImpl)FileBasedIndex.getInstance();
|
||||
FileType fileType = file.getFileType();
|
||||
return IdIndex.isIndexable(fileType) && fileBasedIndex.isIndexingCandidate(file, IdIndex.NAME);
|
||||
}
|
||||
|
||||
private static boolean iterateAll(@NotNull VirtualFile[] files, @NotNull final GlobalSearchScope searchScope, @NotNull final ContentIterator iterator) {
|
||||
final FileTypeManager fileTypeManager = FileTypeManager.getInstance();
|
||||
final VirtualFileFilter contentFilter = new VirtualFileFilter() {
|
||||
@@ -361,6 +367,15 @@ class FindInProjectTask {
|
||||
String text = myFindModel.getStringToFind();
|
||||
if (StringUtil.isEmptyOrSpaces(text)) return false;
|
||||
|
||||
if (hasTrigrams(text)) return true;
|
||||
|
||||
// $ is used to separate words when indexing plain-text files but not when indexing
|
||||
// Java identifiers, so we can't consistently break a string containing $ characters into words
|
||||
|
||||
return myFindModel.isWholeWordsOnly() && text.indexOf('$') < 0 && !StringUtil.getWordsInStringLongestFirst(text).isEmpty();
|
||||
}
|
||||
|
||||
private static boolean hasTrigrams(String text) {
|
||||
if (TrigramIndex.ENABLED) {
|
||||
return !TrigramBuilder.processTrigrams(text, new TrigramBuilder.TrigramProcessor() {
|
||||
@Override
|
||||
@@ -369,11 +384,7 @@ class FindInProjectTask {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// $ is used to separate words when indexing plain-text files but not when indexing
|
||||
// Java identifiers, so we can't consistently break a string containing $ characters into words
|
||||
|
||||
return myFindModel.isWholeWordsOnly() && text.indexOf('$') < 0 && !StringUtil.getWordsInStringLongestFirst(text).isEmpty();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
package com.intellij.find.ngrams;
|
||||
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.util.ThreadLocalCachedIntArray;
|
||||
import com.intellij.openapi.util.text.TrigramBuilder;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -48,16 +49,14 @@ public class TrigramIndex extends ScalarIndexExtension<Integer> implements Custo
|
||||
private static final FileBasedIndex.InputFilter INPUT_FILTER = new FileBasedIndex.InputFilter() {
|
||||
@Override
|
||||
public boolean acceptInput(@NotNull VirtualFile file) {
|
||||
return !file.getFileType().isBinary();
|
||||
}
|
||||
};
|
||||
private static final FileBasedIndex.InputFilter NO_FILES = new FileBasedIndex.InputFilter() {
|
||||
@Override
|
||||
public boolean acceptInput(@NotNull VirtualFile file) {
|
||||
return false;
|
||||
return isIndexable(file.getFileType());
|
||||
}
|
||||
};
|
||||
|
||||
public static boolean isIndexable(FileType fileType) {
|
||||
return ENABLED && !fileType.isBinary();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ID<Integer, Void> getName() {
|
||||
@@ -88,12 +87,7 @@ public class TrigramIndex extends ScalarIndexExtension<Integer> implements Custo
|
||||
@NotNull
|
||||
@Override
|
||||
public FileBasedIndex.InputFilter getInputFilter() {
|
||||
if (ENABLED) {
|
||||
return INPUT_FILTER;
|
||||
}
|
||||
else {
|
||||
return NO_FILES;
|
||||
}
|
||||
return INPUT_FILTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user