mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
VSearch: fix tag search
"abc def" to search file with tag "abc" and "def".
This commit is contained in:
parent
e1091e0d80
commit
4b0152c606
@ -505,20 +505,58 @@ VSearchResultItem *VSearch::searchForTag(const VFile *p_file) const
|
||||
|
||||
const VNoteFile *file = static_cast<const VNoteFile *>(p_file);
|
||||
const QStringList &tags = file->getTags();
|
||||
for (auto const & tag: tags) {
|
||||
|
||||
VSearchToken &contentToken = m_config->m_contentToken;
|
||||
bool singleToken = contentToken.tokenSize() == 1;
|
||||
if (!singleToken) {
|
||||
contentToken.startBatchMode();
|
||||
}
|
||||
|
||||
VSearchResultItem *item = NULL;
|
||||
bool allMatched = false;
|
||||
|
||||
for (int i = 0; i < tags.size(); ++i) {
|
||||
const QString &tag = tags[i];
|
||||
if (tag.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (matchNonContent(tag)) {
|
||||
return new VSearchResultItem(VSearchResultItem::Note,
|
||||
bool matched = false;
|
||||
if (singleToken) {
|
||||
matched = contentToken.matched(tag);
|
||||
} else {
|
||||
matched = contentToken.matchBatchMode(tag);
|
||||
}
|
||||
|
||||
if (matched) {
|
||||
if (!item) {
|
||||
item = new VSearchResultItem(VSearchResultItem::Note,
|
||||
VSearchResultItem::LineNumber,
|
||||
file->getName(),
|
||||
file->fetchPath());
|
||||
}
|
||||
|
||||
VSearchResultSubItem sitem(i, tag);
|
||||
item->m_matches.append(sitem);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
if (!singleToken && contentToken.readyToEndBatchMode(allMatched)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!singleToken) {
|
||||
contentToken.readyToEndBatchMode(allMatched);
|
||||
contentToken.endBatchMode();
|
||||
|
||||
if (!allMatched && item) {
|
||||
// This file does not meet all the tokens.
|
||||
delete item;
|
||||
item = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
VSearchResultItem *VSearch::searchForContent(const VFile *p_file) const
|
||||
|
@ -429,10 +429,10 @@ struct VSearchConfig
|
||||
// Wildcard pattern to filter file.
|
||||
QString m_pattern;
|
||||
|
||||
// Token for name, outline, and tag.
|
||||
// Token for name, outline.
|
||||
VSearchToken m_token;
|
||||
|
||||
// Token for content.
|
||||
// Token for content and tag.
|
||||
VSearchToken m_contentToken;
|
||||
};
|
||||
|
||||
@ -538,7 +538,7 @@ struct VSearchResult
|
||||
{
|
||||
friend class VSearch;
|
||||
|
||||
VSearchResult(VSearch *p_search)
|
||||
explicit VSearchResult(VSearch *p_search)
|
||||
: m_state(VSearchState::Idle),
|
||||
m_search(p_search)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user