Skip to content

Commit 07257f0

Browse files
author
tpat
committed
Added documentation and examples for fuzzy search in Help > New Features > Module Fuzzy
Search. Fuzzy search no longer searches permutations because the cost was factorial(!). Instead, it now searches every word once(linear cost) which has the side effect of ignoring redundancy.
1 parent f111009 commit 07257f0

File tree

6 files changed

+61
-71
lines changed

6 files changed

+61
-71
lines changed

src/Interface/Application/SCIRunMainWindow.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ SCIRunMainWindow::SCIRunMainWindow()
205205
connect(actionCreateToolkitFromDirectory_, SIGNAL(triggered()), this, SLOT(helpWithToolkitCreation()));
206206

207207
connect(helpActionPythonAPI_, SIGNAL(triggered()), this, SLOT(loadPythonAPIDoc()));
208+
connect(helpActionModuleFuzzySearch_, SIGNAL(triggered()), this, SLOT(showModuleFuzzySearchHelp()));
208209
connect(helpActionSnippets_, SIGNAL(triggered()), this, SLOT(showSnippetHelp()));
209210
connect(helpActionClipboard_, SIGNAL(triggered()), this, SLOT(showClipboardHelp()));
210211
connect(helpActionTagLayer_, SIGNAL(triggered()), this, SLOT(showTagHelp()));

src/Interface/Application/SCIRunMainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ private Q_SLOTS:
280280
void showSnippetHelp();
281281
void showTagHelp();
282282
void showTriggerHelp();
283+
void showModuleFuzzySearchHelp();
283284
void switchMouseMode();
284285
void toggleFullScreen();
285286
void toggleMetadataLayer(bool toggle);

src/Interface/Application/SCIRunMainWindow.ui

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
<string>Learn About New Features</string>
184184
</property>
185185
<addaction name="helpActionSnippets_"/>
186+
<addaction name="helpActionModuleFuzzySearch_"/>
186187
<addaction name="helpActionMetadataLayer_"/>
187188
<addaction name="helpActionTagLayer_"/>
188189
<addaction name="helpActionPythonInterpreter_"/>
@@ -1054,6 +1055,11 @@
10541055
<string>*Import 4.x network file...</string>
10551056
</property>
10561057
</action>
1058+
<action name="helpActionModuleFuzzySearch_">
1059+
<property name="text">
1060+
<string>Module Fuzzy Search</string>
1061+
</property>
1062+
</action>
10571063
<action name="helpActionSnippets_">
10581064
<property name="text">
10591065
<string>Snippets</string>

src/Interface/Application/SCIRunMainWindowSlotsPrivate.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,20 @@ void SCIRunMainWindow::showTriggerHelp()
773773
);
774774
}
775775

776+
void SCIRunMainWindow::showModuleFuzzySearchHelp()
777+
{
778+
QMessageBox::information(this, "Module Selector Fuzzy Search",
779+
"\nFuzzy search lets you skip characters as long as the are in order."
780+
"\nExample: Searching 'rdfl' will find the module 'ReadField'."
781+
"\n\nSearches are case insensitive except when you type an upper case character."
782+
"\nExample: Searching 'RdFl' or 'Rdfl' will reduce total matches while still finding 'ReadField'."
783+
"\nTip: Type the first letters of words in capitals, such as 'SFG' to find 'ShowFieldGlyphs'."
784+
"\n\nSpaces between words will do multiple searches to further reduce matched modules."
785+
"\nExample: Search 'mesh get' to search both 'mesh' and 'get' in the same module name."
786+
"\n\nAll symbols are igonred except *'s which will make the search switch to the wildcards option instead of fuzzy search."
787+
);
788+
}
789+
776790
void SCIRunMainWindow::toolkitDownload()
777791
{
778792
auto action = qobject_cast<QAction*>(sender());

src/Interface/Application/TreeViewCollaborators.cc

Lines changed: 37 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ bool HideItemsNotMatchingString::shouldHide(QTreeWidgetItem* item)
8686
|| boost::contains(start_, "*"))
8787
return !match_.exactMatch(text);
8888
else
89-
return !fuzzySearch(text, start_);
89+
return !fuzzySearchAllPatterns(text, start_);
9090
}
9191

92-
bool HideItemsNotMatchingString::fuzzySearch(QString text, QString pattern)
92+
bool HideItemsNotMatchingString::fuzzySearchAllPatterns(const QString& text, const QString& pattern)
9393
{
9494
std::string pattern_str = removeAllSpecialCharacters(pattern.toStdString());
9595
std::vector<std::string> pattern_split;
@@ -103,13 +103,43 @@ bool HideItemsNotMatchingString::fuzzySearch(QString text, QString pattern)
103103
if(pattern_split[i].empty())
104104
pattern_split.erase(pattern_split.begin() + i);
105105
}
106-
// Checks permutations of the first 8 words given
107-
if(pattern_split.size() > 8)
108-
pattern_split.resize(8);
109106

110-
std::vector<bool> visited(pattern_split.size(), false);
107+
// Every word in the pattern must match
108+
for(std::string str : pattern_split)
109+
{
110+
if(!fuzzySearch(text.toStdString(), str))
111+
{
112+
return false;
113+
}
114+
}
111115

112-
return fuzzySearchRemainingPatterns(visited, pattern_split, text, 0);
116+
return true;
117+
}
118+
119+
bool HideItemsNotMatchingString::fuzzySearch(const std::string& text, const std::string& pattern)
120+
{
121+
int patternIndex = 0;
122+
123+
for(int t = 0; t < text.length(); t++)
124+
{
125+
bool isUpperChar = pattern[patternIndex] < 97;
126+
127+
// Counts as a match if letter found. Only case sensitive if search char is upper case
128+
if((isUpperChar && (text[t] == pattern[patternIndex]))
129+
|| (!isUpperChar && (std::tolower(text[t]) == std::tolower(pattern[patternIndex]))))
130+
{
131+
++patternIndex;
132+
}
133+
134+
// Matched if pattern reaches end of string
135+
if(patternIndex >= pattern.length())
136+
{
137+
return true;
138+
}
139+
}
140+
141+
// Return false if all the letters did not match
142+
return false;
113143
}
114144

115145
std::string HideItemsNotMatchingString::removeAllSpecialCharacters(const std::string& str)
@@ -127,65 +157,6 @@ std::string HideItemsNotMatchingString::removeAllSpecialCharacters(const std::st
127157
return newStr;
128158
}
129159

130-
bool HideItemsNotMatchingString::fuzzySearchRemainingPatterns(std::vector<bool>& visited,
131-
std::vector<std::string>& patternSplit,
132-
QString& text,
133-
int textIndex)
134-
{
135-
// Find current pattern
136-
std::string currentPattern;
137-
for(int i = 0; i < visited.size(); i++)
138-
{
139-
if(!visited[i])
140-
{
141-
visited[i] = true;
142-
currentPattern = patternSplit[i];
143-
144-
// Do search
145-
int patternIndex = 0;
146-
int currentTextIndex = textIndex;
147-
bool matched = false;
148-
149-
for(int t = currentTextIndex; t < text.length(); t++)
150-
{
151-
bool isUpperChar = currentPattern[patternIndex] < 97;
152-
153-
// Counts as a match if letter found
154-
if((isUpperChar && (text[t] == currentPattern[patternIndex]))
155-
|| (!isUpperChar && (text[t].toLower() == std::tolower(currentPattern[patternIndex]))))
156-
{
157-
++patternIndex;
158-
currentTextIndex = t;
159-
}
160-
161-
if(patternIndex >= currentPattern.length())
162-
{
163-
matched = true;
164-
break;
165-
}
166-
}
167-
168-
// If current matched, check the rest of remaining permutations
169-
bool remainingMatched = false;
170-
if(matched)
171-
{
172-
remainingMatched = fuzzySearchRemainingPatterns(visited, patternSplit, text, currentTextIndex);
173-
if(remainingMatched)
174-
return true;
175-
}
176-
visited[i] = false;
177-
}
178-
}
179-
180-
for(int i = 0; i < visited.size(); i++)
181-
{
182-
if(!visited[i])
183-
return false;
184-
}
185-
186-
return true;
187-
}
188-
189160
void ShowAll::operator()(QTreeWidgetItem* item)
190161
{
191162
item->setHidden(false);

src/Interface/Application/TreeViewCollaborators.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,9 @@ namespace Gui {
7171

7272
void operator()(QTreeWidgetItem* item);
7373
bool shouldHide(QTreeWidgetItem* item);
74-
bool fuzzySearch(QString text, QString pattern);
74+
bool fuzzySearchAllPatterns(const QString& text, const QString& pattern);
75+
bool fuzzySearch(const std::string& text, const std::string& pattern);
7576
std::string removeAllSpecialCharacters(const std::string& str);
76-
bool fuzzySearchRemainingPatterns(std::vector<bool>& visited,
77-
std::vector<std::string>& patternSplit,
78-
QString& text,
79-
int textIndex);
8077
};
8178

8279
struct ShowAll

0 commit comments

Comments
 (0)