xapian search string highlight

This commit is contained in:
Xiao YiFang 2022-10-06 12:39:24 +08:00
parent 83b36a7316
commit 83e59c0510

View file

@ -565,10 +565,10 @@ void FullTextSearchDialog::itemClicked( const QModelIndex & idx )
#ifdef USE_XAPIAN #ifdef USE_XAPIAN
auto searchText = ui.searchLine->text(); auto searchText = ui.searchLine->text();
searchText.replace( searchText.replace(
QRegularExpression( "[\\*\\?\\+\\\"]|\\bAnd\\b|\\bOR\\b", QRegularExpression::CaseInsensitiveOption ), QRegularExpression( "[\\*\\?\\+]|\\bAnd\\b|\\bOR\\b", QRegularExpression::CaseInsensitiveOption ),
" " ); " " );
QRegularExpression tokenRx("\\\".*?\\\"|[\\w\\+\\-]+",QRegularExpression::DotMatchesEverythingOption|QRegularExpression::CaseInsensitiveOption); QRegularExpression tokenRx("(\".*?\")|([\\w\\+\\-]+)",QRegularExpression::DotMatchesEverythingOption|QRegularExpression::CaseInsensitiveOption);
auto it = tokenRx.globalMatch(searchText); auto it = tokenRx.globalMatch(searchText);
QString firstAvailbeItem; QString firstAvailbeItem;
while( it.hasNext() ) while( it.hasNext() )
@ -578,6 +578,12 @@ void FullTextSearchDialog::itemClicked( const QModelIndex & idx )
auto p = match.captured(); auto p = match.captured();
if( p.startsWith( '-' ) ) if( p.startsWith( '-' ) )
continue; continue;
//the searched text should be like "term".remove enclosed double quotation marks.
if(p.startsWith("\"")){
p.remove("\"");
}
firstAvailbeItem = p; firstAvailbeItem = p;
break; break;
} }