logic: Fixed issues in search
* fixed bad search performance when rescoring * fixed commands had no text in autocompletions * no autocompletions when entering fulltext search query * check query actuality before processing autocompletions
This commit is contained in:
@@ -71,8 +71,16 @@ void SearchController::handleMessage(MessageSearchAutocomplete* message)
|
|||||||
{
|
{
|
||||||
TRACE("search autocomplete");
|
TRACE("search autocomplete");
|
||||||
|
|
||||||
|
SearchView* view = getView();
|
||||||
|
|
||||||
|
// Don't autocomplete if autocompletion request is not up-to-date anymore
|
||||||
|
if (message->query != view->getQuery())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
LOG_INFO("autocomplete string: \"" + message->query + "\"");
|
LOG_INFO("autocomplete string: \"" + message->query + "\"");
|
||||||
getView()->setAutocompletionList(m_storageAccess->getAutocompletionMatches(message->query));
|
view->setAutocompletionList(m_storageAccess->getAutocompletionMatches(message->query));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::handleMessage(MessageSearchFullText* message)
|
void SearchController::handleMessage(MessageSearchFullText* message)
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ public:
|
|||||||
|
|
||||||
virtual std::string getName() const;
|
virtual std::string getName() const;
|
||||||
|
|
||||||
|
virtual std::string getQuery() const = 0;
|
||||||
|
|
||||||
virtual void setMatches(const std::vector<SearchMatch>& matches) = 0;
|
virtual void setMatches(const std::vector<SearchMatch>& matches) = 0;
|
||||||
|
|
||||||
virtual void setFocus() = 0;
|
virtual void setFocus() = 0;
|
||||||
|
|||||||
@@ -503,9 +503,11 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionMatches(const std::
|
|||||||
|
|
||||||
// search in indices
|
// search in indices
|
||||||
size_t maxResultsCount = 100;
|
size_t maxResultsCount = 100;
|
||||||
|
size_t maxBestScoredResultsLength = 100;
|
||||||
|
|
||||||
std::vector<SearchResult> results;
|
std::vector<SearchResult> results;
|
||||||
utility::append(results, m_commandIndex.search(query, 0));
|
utility::append(results, m_commandIndex.search(query, 0));
|
||||||
utility::append(results, m_elementIndex.search(query, maxResultsCount, 100));
|
utility::append(results, m_elementIndex.search(query, maxResultsCount, maxBestScoredResultsLength));
|
||||||
utility::append(results, m_fileIndex.search(query, 20));
|
utility::append(results, m_fileIndex.search(query, 20));
|
||||||
|
|
||||||
// fetch StorageNodes for node ids
|
// fetch StorageNodes for node ids
|
||||||
@@ -556,6 +558,7 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionMatches(const std::
|
|||||||
}
|
}
|
||||||
|
|
||||||
match.name = result.text;
|
match.name = result.text;
|
||||||
|
match.text = result.text;
|
||||||
match.indices = result.indices;
|
match.indices = result.indices;
|
||||||
match.score = result.score;
|
match.score = result.score;
|
||||||
|
|
||||||
@@ -585,7 +588,9 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionMatches(const std::
|
|||||||
// rescore match
|
// rescore match
|
||||||
if (idx && match.indices.size())
|
if (idx && match.indices.size())
|
||||||
{
|
{
|
||||||
SearchResult newResult = SearchIndex::rescoreText(match.name, match.text, match.indices, match.score);
|
SearchResult newResult =
|
||||||
|
SearchIndex::rescoreText(match.name, match.text, match.indices, match.score, maxBestScoredResultsLength);
|
||||||
|
|
||||||
match.score = newResult.score;
|
match.score = newResult.score;
|
||||||
match.indices = newResult.indices;
|
match.indices = newResult.indices;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -464,6 +464,11 @@ SearchResult SearchIndex::rescoreText(
|
|||||||
textIndices.push_back(idx - (fulltext.size() - text.size()));
|
textIndices.push_back(idx - (fulltext.size() - text.size()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ignore rescoring if result is too long
|
||||||
|
else if (maxBestScoredLength > 0 && fulltext.size() > maxBestScoredLength * 2)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
// try if match is within text
|
// try if match is within text
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ public:
|
|||||||
const std::string& text,
|
const std::string& text,
|
||||||
const std::vector<size_t>& indices,
|
const std::vector<size_t>& indices,
|
||||||
int score,
|
int score,
|
||||||
size_t maxBestScoredLength = 0);
|
size_t maxBestScoredLength);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::shared_ptr<Node>> m_nodes;
|
std::vector<std::shared_ptr<Node>> m_nodes;
|
||||||
|
|||||||
@@ -66,6 +66,11 @@ QSize QtSearchBar::sizeHint() const
|
|||||||
return QSize(400, 100);
|
return QSize(400, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QtSearchBar::query() const
|
||||||
|
{
|
||||||
|
return m_searchBox->text();
|
||||||
|
}
|
||||||
|
|
||||||
void QtSearchBar::setMatches(const std::vector<SearchMatch>& matches)
|
void QtSearchBar::setMatches(const std::vector<SearchMatch>& matches)
|
||||||
{
|
{
|
||||||
m_searchBox->setMatches(matches);
|
m_searchBox->setMatches(matches);
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ public:
|
|||||||
|
|
||||||
virtual QSize sizeHint() const;
|
virtual QSize sizeHint() const;
|
||||||
|
|
||||||
|
QString query() const;
|
||||||
|
|
||||||
void setMatches(const std::vector<SearchMatch>& matches);
|
void setMatches(const std::vector<SearchMatch>& matches);
|
||||||
void setFocus();
|
void setFocus();
|
||||||
void findFulltext();
|
void findFulltext();
|
||||||
|
|||||||
@@ -895,7 +895,7 @@ void QtSmartSearchBox::clearLineEdit()
|
|||||||
|
|
||||||
void QtSmartSearchBox::requestAutoCompletions()
|
void QtSmartSearchBox::requestAutoCompletions()
|
||||||
{
|
{
|
||||||
if (text().size())
|
if (text().size() && !text().startsWith(SearchMatch::FULLTEXT_SEARCH_CHARACTER))
|
||||||
{
|
{
|
||||||
MessageSearchAutocomplete(text().toStdString()).dispatch();
|
MessageSearchAutocomplete(text().toStdString()).dispatch();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,11 @@ void QtSearchView::refreshView()
|
|||||||
m_refreshViewFunctor();
|
m_refreshViewFunctor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string QtSearchView::getQuery() const
|
||||||
|
{
|
||||||
|
return m_widget->query().toStdString();
|
||||||
|
}
|
||||||
|
|
||||||
void QtSearchView::setMatches(const std::vector<SearchMatch>& matches)
|
void QtSearchView::setMatches(const std::vector<SearchMatch>& matches)
|
||||||
{
|
{
|
||||||
m_setMatchesFunctor(matches);
|
m_setMatchesFunctor(matches);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public:
|
|||||||
virtual void refreshView();
|
virtual void refreshView();
|
||||||
|
|
||||||
// SearchView implementation
|
// SearchView implementation
|
||||||
|
virtual std::string getQuery() const;
|
||||||
virtual void setMatches(const std::vector<SearchMatch>& matches);
|
virtual void setMatches(const std::vector<SearchMatch>& matches);
|
||||||
virtual void setFocus();
|
virtual void setFocus();
|
||||||
virtual void findFulltext();
|
virtual void findFulltext();
|
||||||
|
|||||||
Reference in New Issue
Block a user