Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add soft failover to fast search #862

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions far/filelist.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
filelist.cpp

Файловая панель
Expand Down Expand Up @@ -3690,7 +3690,7 @@ bool FileList::FindPartName(string_view const Name,int Next,int Direct)
NameView.remove_suffix(1);
}

const auto strMask = exclude_sets(NameView + L'*');
auto strMask = exclude_sets(NameView + L'*');

const auto Match = [&](int const I)
{
Expand All @@ -3710,17 +3710,24 @@ bool FileList::FindPartName(string_view const Name,int Next,int Direct)
return false;
};


for (int I=m_CurFile+(Next?Direct:0); I >= 0 && I < static_cast<int>(m_ListData.size()); I+=Direct)
//Две попытки найти нужный файл - сначала строгий поиск по началам строк, потом более мягкий по серединам строк
//TODO: в будущем можно добавить опцию в настройки (выполнять или не выполнять вторую попытку)
for (int attempt=0; attempt<2; attempt++)
{
if (Match(I))
return true;
}
for (int I=m_CurFile+(Next?Direct:0); I >= 0 && I < static_cast<int>(m_ListData.size()); I+=Direct)
{
if (Match(I))
return true;
}

for (int I=(Direct > 0)?0:static_cast<int>(m_ListData.size()-1); (Direct > 0) ? I < m_CurFile:I > m_CurFile; I+=Direct)
{
if (Match(I))
return true;
for (int I=(Direct > 0)?0:static_cast<int>(m_ListData.size()-1); (Direct > 0) ? I < m_CurFile:I > m_CurFile; I+=Direct)
{
if (Match(I))
return true;
}
//Смягчаем критерий поиска, если строгий поиск ни к чему не привёл, и повторяем попытку
if (!strMask.starts_with(L'*'))
strMask = L'*' + strMask;
}

return false;
Expand Down