From 83e59c0510f41f78103b759fe62ce2f368ecc007 Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Thu, 6 Oct 2022 12:39:24 +0800 Subject: [PATCH] xapian search string highlight --- fulltextsearch.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fulltextsearch.cc b/fulltextsearch.cc index 7bfa3c7a..ac6d1876 100644 --- a/fulltextsearch.cc +++ b/fulltextsearch.cc @@ -565,10 +565,10 @@ void FullTextSearchDialog::itemClicked( const QModelIndex & idx ) #ifdef USE_XAPIAN auto searchText = ui.searchLine->text(); 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); QString firstAvailbeItem; while( it.hasNext() ) @@ -578,6 +578,12 @@ void FullTextSearchDialog::itemClicked( const QModelIndex & idx ) auto p = match.captured(); if( p.startsWith( '-' ) ) continue; + + //the searched text should be like "term".remove enclosed double quotation marks. + if(p.startsWith("\"")){ + p.remove("\""); + } + firstAvailbeItem = p; break; }