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 VNoteFile *file = static_cast<const VNoteFile *>(p_file);
|
||||||
const QStringList &tags = file->getTags();
|
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()) {
|
if (tag.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchNonContent(tag)) {
|
bool matched = false;
|
||||||
return new VSearchResultItem(VSearchResultItem::Note,
|
if (singleToken) {
|
||||||
VSearchResultItem::LineNumber,
|
matched = contentToken.matched(tag);
|
||||||
file->getName(),
|
} else {
|
||||||
file->fetchPath());
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!singleToken && contentToken.readyToEndBatchMode(allMatched)) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
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
|
VSearchResultItem *VSearch::searchForContent(const VFile *p_file) const
|
||||||
|
@ -429,10 +429,10 @@ struct VSearchConfig
|
|||||||
// Wildcard pattern to filter file.
|
// Wildcard pattern to filter file.
|
||||||
QString m_pattern;
|
QString m_pattern;
|
||||||
|
|
||||||
// Token for name, outline, and tag.
|
// Token for name, outline.
|
||||||
VSearchToken m_token;
|
VSearchToken m_token;
|
||||||
|
|
||||||
// Token for content.
|
// Token for content and tag.
|
||||||
VSearchToken m_contentToken;
|
VSearchToken m_contentToken;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -538,7 +538,7 @@ struct VSearchResult
|
|||||||
{
|
{
|
||||||
friend class VSearch;
|
friend class VSearch;
|
||||||
|
|
||||||
VSearchResult(VSearch *p_search)
|
explicit VSearchResult(VSearch *p_search)
|
||||||
: m_state(VSearchState::Idle),
|
: m_state(VSearchState::Idle),
|
||||||
m_search(p_search)
|
m_search(p_search)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user