logic: preselecting SearchNodes for autocompletion by prefiltering the Graph with the entered Query

This change only shows matches in the autocompletion list that are prefiltered by the already entered query. The
autocompletion now also shows up after an operator of type . or > has been entered to show an alphabetical list of
possible tokens.
This commit is contained in:
Eberhard Graether
2014-10-28 20:21:19 +01:00
parent ede0af4291
commit 86f4629b0d
27 changed files with 407 additions and 198 deletions
+4 -4
View File
@@ -108,7 +108,7 @@ public:
void test_operator_sub()
{
TS_ASSERT_EQUALS(
printedFilteredTestGraph("'class'>'base'"),
printedFilteredTestGraph("'class'.'base'"),
"1 nodes: class:A\n"
"0 edges:\n"
@@ -118,7 +118,7 @@ public:
void test_operator_has()
{
TS_ASSERT_EQUALS(
printedFilteredTestGraph("\"A\".'field'"),
printedFilteredTestGraph("\"A\">'field'"),
"1 nodes: field:A::count\n"
"0 edges:\n"
@@ -138,7 +138,7 @@ public:
void test_operator_group()
{
TS_ASSERT_EQUALS(
printedFilteredTestGraph("('static'|'const')>'public'"),
printedFilteredTestGraph("('static'|'const').'public'"),
"1 nodes: method:A::getCount\n"
"0 edges:\n"
@@ -165,7 +165,7 @@ private:
{
createTestStorage();
std::vector<SearchIndex::SearchMatch> matches = m_storage->getAutocompletionMatches(name);
std::vector<SearchIndex::SearchMatch> matches = m_storage->getAutocompletionMatches("", name);
if (matches.size() && matches[0].fullName == name)
{
return matches[0].tokenIds;
+6 -6
View File
@@ -75,7 +75,7 @@ public:
"A \" INVALID\n"
" \"A\"\n"
"> IMPLICIT\n"
". IMPLICIT\n"
" \"\"\n"
);
}
@@ -276,7 +276,7 @@ public:
"\"A\" ( \"B\" )\n"
" \"A\"\n"
"> IMPLICIT\n"
". IMPLICIT\n"
" (\"B\")\n"
);
}
@@ -298,13 +298,13 @@ public:
void test_operator_precedence_has_before_sub()
{
TS_ASSERT_EQUALS(
printedQueryTree("'namespace'.'class'>'base'"),
printedQueryTree("'namespace'>'class'.'base'"),
"'namespace' . 'class' > 'base'\n"
"'namespace' > 'class' . 'base'\n"
" 'namespace'\n"
" .\n"
" >\n"
" 'class'\n"
">\n"
".\n"
" 'base'\n"
);
}
+20 -43
View File
@@ -6,14 +6,6 @@
class SearchIndexTestSuite : public CxxTest::TestSuite
{
public:
// void clear();
// SearchNode* addNode(const std::string& fullName);
// SearchNode* getNode(const std::string& fullName) const;
// std::vector<std::string> findFuzzyMatches(const std::string& query) const;
void test_add_node()
{
SearchIndex index;
@@ -100,7 +92,7 @@ public:
index.addNode(utility::splitToVector("math", "::"));
index.addNode(utility::splitToVector("string", "::"));
std::vector<SearchIndex::SearchMatch> matches = index.findFuzzyMatches("u");
std::vector<SearchIndex::SearchMatch> matches = index.runFuzzySearchAndGetMatches("u");
TS_ASSERT_EQUALS(1, matches.size());
TS_ASSERT_EQUALS("util", matches[0].fullName);
@@ -108,8 +100,15 @@ public:
TS_ASSERT_EQUALS(1, matches[0].indices.size());
TS_ASSERT_EQUALS(0, matches[0].indices[0]);
matches = index.findFuzzyMatches("");
TS_ASSERT_EQUALS(0, matches.size());
matches = index.runFuzzySearchAndGetMatches("");
TS_ASSERT_EQUALS(3, matches.size());
TS_ASSERT_EQUALS("math", matches[0].fullName);
TS_ASSERT_EQUALS("string", matches[1].fullName);
TS_ASSERT_EQUALS("util", matches[2].fullName);
TS_ASSERT_EQUALS(0, matches[0].weight);
TS_ASSERT_EQUALS(0, matches[1].weight);
TS_ASSERT_EQUALS(0, matches[2].weight);
}
void test_fuzzy_matching_is_case_insensitive()
@@ -118,13 +117,13 @@ public:
index.addNode(utility::splitToVector("util", "::"));
index.addNode(utility::splitToVector("MATH", "::"));
std::vector<SearchIndex::SearchMatch> matches = index.findFuzzyMatches("t");
std::vector<SearchIndex::SearchMatch> matches = index.runFuzzySearchAndGetMatches("t");
TS_ASSERT_EQUALS(2, matches.size());
TS_ASSERT_EQUALS("MATH", matches[0].fullName);
TS_ASSERT_EQUALS("util", matches[1].fullName);
matches = index.findFuzzyMatches("T");
matches = index.runFuzzySearchAndGetMatches("T");
TS_ASSERT_EQUALS(2, matches.size());
TS_ASSERT_EQUALS("MATH", matches[0].fullName);
@@ -138,7 +137,7 @@ public:
index.addNode(utility::splitToVector("math", "::"));
index.addNode(utility::splitToVector("string", "::"));
std::vector<SearchIndex::SearchMatch> matches = index.findFuzzyMatches("t");
std::vector<SearchIndex::SearchMatch> matches = index.runFuzzySearchAndGetMatches("t");
TS_ASSERT_EQUALS(3, matches.size());
TS_ASSERT_EQUALS("string", matches[0].fullName);
@@ -161,7 +160,7 @@ public:
index.addNode(utility::splitToVector("uTil", "::"));
index.addNode(utility::splitToVector("string", "::"));
std::vector<SearchIndex::SearchMatch> matches = index.findFuzzyMatches("t");
std::vector<SearchIndex::SearchMatch> matches = index.runFuzzySearchAndGetMatches("t");
TS_ASSERT_EQUALS(2, matches.size());
TS_ASSERT_EQUALS("uTil", matches[0].fullName);
@@ -174,7 +173,7 @@ public:
index.addNode(utility::splitToVector("oaabbcc", "::"));
index.addNode(utility::splitToVector("ocbaabc", "::"));
std::vector<SearchIndex::SearchMatch> matches = index.findFuzzyMatches("abc");
std::vector<SearchIndex::SearchMatch> matches = index.runFuzzySearchAndGetMatches("abc");
TS_ASSERT_EQUALS(2, matches.size());
TS_ASSERT_EQUALS("ocbaabc", matches[0].fullName);
@@ -188,12 +187,12 @@ public:
index.addNode(utility::splitToVector("util::math::floor", "::"));
index.addNode(utility::splitToVector("util::string::concat", "::"));
std::vector<SearchIndex::SearchMatch> matches = index.findFuzzyMatches("t");
std::vector<SearchIndex::SearchMatch> matches = index.runFuzzySearchAndGetMatches("t");
TS_ASSERT_EQUALS(1, matches.size());
TS_ASSERT_EQUALS("util", matches[0].fullName);
matches = index.findFuzzyMatches("uml");
matches = index.runFuzzySearchAndGetMatches("uml");
TS_ASSERT_EQUALS(2, matches.size());
TS_ASSERT_EQUALS("util::math::floor", matches[0].fullName);
@@ -207,13 +206,13 @@ public:
index.addNode(utility::splitToVector("util::math::floor", "::"));
index.addNode(utility::splitToVector("util::string::concat", "::"));
std::vector<SearchIndex::SearchMatch> matches = index.findFuzzyMatches("u:i");
std::vector<SearchIndex::SearchMatch> matches = index.runFuzzySearchAndGetMatches("u:i");
TS_ASSERT_EQUALS(2, matches.size());
TS_ASSERT_EQUALS("util::string", matches[0].fullName);
TS_ASSERT_EQUALS("util::math::ceil", matches[1].fullName);
matches = index.findFuzzyMatches("u:t:i");
matches = index.runFuzzySearchAndGetMatches("u:t:i");
TS_ASSERT_EQUALS(1, matches.size());
TS_ASSERT_EQUALS("util::math::ceil", matches[0].fullName);
@@ -225,32 +224,10 @@ public:
index.addNode(utility::splitToVector("abc::dfe::ghi", "::"));
index.addNode(utility::splitToVector("abc::hgi", "::"));
std::vector<SearchIndex::SearchMatch> matches = index.findFuzzyMatches("g");
std::vector<SearchIndex::SearchMatch> matches = index.runFuzzySearchAndGetMatches("g");
TS_ASSERT_EQUALS(2, matches.size());
TS_ASSERT_EQUALS("abc::dfe::ghi", matches[0].fullName);
TS_ASSERT_EQUALS("abc::hgi", matches[1].fullName);
}
void test_fuzzy_matching_with_defined_start_node()
{
SearchIndex index;
index.addNode(utility::splitToVector("math::ceil", "::"));
index.addNode(utility::splitToVector("math::floor", "::"));
index.addNode(utility::splitToVector("string::concat", "::"));
std::vector<SearchIndex::SearchMatch> matches = index.findFuzzyMatches("\"math\"c");
TS_ASSERT_EQUALS(1, matches.size());
TS_ASSERT_EQUALS("math::ceil", matches[0].fullName);
matches = index.findFuzzyMatches("\"mathc");
TS_ASSERT_EQUALS(0, matches.size());
matches = index.findFuzzyMatches("math\"c");
TS_ASSERT_EQUALS(0, matches.size());
matches = index.findFuzzyMatches("\"mat\"h\"c");
TS_ASSERT_EQUALS(0, matches.size());
}
};
+10
View File
@@ -236,4 +236,14 @@ public:
TS_ASSERT(!utility::equalsCaseInsensitive(foo, foo2));
}
void test_replace()
{
TS_ASSERT_EQUALS("fubar", utility::replace("foobar", "oo", "u"));
TS_ASSERT_EQUALS("fuuuubar", utility::replace("foobar", "o", "uu"));
TS_ASSERT_EQUALS("bar", utility::replace("foobar", "foo", ""));
TS_ASSERT_EQUALS("foobar", utility::replace("foobar", "", "i"));
TS_ASSERT_EQUALS("foobar", utility::replace("foobar", "", ""));
TS_ASSERT_EQUALS("", utility::replace("", "foo", "bar"));
TS_ASSERT_EQUALS("foobar", utility::replace("foobar", "ba", "ba"));
}
};