mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
xapian search string highlight
This commit is contained in:
parent
83b36a7316
commit
83e59c0510
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue