mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-12-04 16:14:05 +00:00
opt: add fullindex position (#916)
* opt: enable fulltext with position info
* opt: add fulltext position support
* 🎨 apply clang-format changes
* i18n: update translation entries
* opt: default enablePosition=false
* opt: fulltext search highlight
---------
Co-authored-by: xiaoyifang <xiaoyifang@users.noreply.github.com>
This commit is contained in:
parent
beab8e8e39
commit
8b88ea544e
1602
locale/crowdin.ts
1602
locale/crowdin.ts
File diff suppressed because it is too large
Load diff
|
@ -1030,6 +1030,10 @@ Class load()
|
||||||
if ( !fts.namedItem( "enabled" ).isNull() )
|
if ( !fts.namedItem( "enabled" ).isNull() )
|
||||||
c.preferences.fts.enabled = ( fts.namedItem( "enabled" ).toElement().text() == "1" );
|
c.preferences.fts.enabled = ( fts.namedItem( "enabled" ).toElement().text() == "1" );
|
||||||
|
|
||||||
|
if ( !fts.namedItem( "enablePosition" ).isNull() ) {
|
||||||
|
c.preferences.fts.enablePosition = ( fts.namedItem( "enablePosition" ).toElement().text() == "1" );
|
||||||
|
}
|
||||||
|
|
||||||
if ( !fts.namedItem( "maxDictionarySize" ).isNull() )
|
if ( !fts.namedItem( "maxDictionarySize" ).isNull() )
|
||||||
c.preferences.fts.maxDictionarySize = fts.namedItem( "maxDictionarySize" ).toElement().text().toUInt();
|
c.preferences.fts.maxDictionarySize = fts.namedItem( "maxDictionarySize" ).toElement().text().toUInt();
|
||||||
}
|
}
|
||||||
|
@ -2018,6 +2022,10 @@ void save( Class const & c )
|
||||||
opt.appendChild( dd.createTextNode( c.preferences.fts.enabled ? "1" : "0" ) );
|
opt.appendChild( dd.createTextNode( c.preferences.fts.enabled ? "1" : "0" ) );
|
||||||
hd.appendChild( opt );
|
hd.appendChild( opt );
|
||||||
|
|
||||||
|
opt = dd.createElement( "enablePosition" );
|
||||||
|
opt.appendChild( dd.createTextNode( c.preferences.fts.enablePosition ? "1" : "0" ) );
|
||||||
|
hd.appendChild( opt );
|
||||||
|
|
||||||
opt = dd.createElement( "maxDictionarySize" );
|
opt = dd.createElement( "maxDictionarySize" );
|
||||||
opt.appendChild( dd.createTextNode( QString::number( c.preferences.fts.maxDictionarySize ) ) );
|
opt.appendChild( dd.createTextNode( QString::number( c.preferences.fts.maxDictionarySize ) ) );
|
||||||
hd.appendChild( opt );
|
hd.appendChild( opt );
|
||||||
|
|
|
@ -176,6 +176,8 @@ struct FullTextSearch
|
||||||
int searchMode;
|
int searchMode;
|
||||||
bool enabled;
|
bool enabled;
|
||||||
|
|
||||||
|
bool enablePosition = false;
|
||||||
|
|
||||||
quint32 maxDictionarySize;
|
quint32 maxDictionarySize;
|
||||||
QByteArray dialogGeometry;
|
QByteArray dialogGeometry;
|
||||||
QString disabledTypes;
|
QString disabledTypes;
|
||||||
|
|
|
@ -240,7 +240,14 @@ void makeFTSIndex( BtreeIndexing::BtreeDictionary * dict, QAtomicInt & isCancell
|
||||||
Xapian::Document doc;
|
Xapian::Document doc;
|
||||||
|
|
||||||
indexer.set_document( doc );
|
indexer.set_document( doc );
|
||||||
|
|
||||||
|
if ( GlobalBroadcaster::instance()->getPreference()->fts.enablePosition ) {
|
||||||
|
indexer.index_text( articleStr.toStdString() );
|
||||||
|
}
|
||||||
|
else {
|
||||||
indexer.index_text_without_positions( articleStr.toStdString() );
|
indexer.index_text_without_positions( articleStr.toStdString() );
|
||||||
|
}
|
||||||
|
|
||||||
doc.set_data( std::to_string( address ) );
|
doc.set_data( std::to_string( address ) );
|
||||||
// Add the document to the database.
|
// Add the document to the database.
|
||||||
db.add_document( doc );
|
db.add_document( doc );
|
||||||
|
|
|
@ -2280,18 +2280,10 @@ void ArticleView::highlightFTSResults()
|
||||||
//if application goes here,that means the article text must contains the search text.
|
//if application goes here,that means the article text must contains the search text.
|
||||||
//whole word match regString will contain \b . can not match the above senario.
|
//whole word match regString will contain \b . can not match the above senario.
|
||||||
//workaround ,remove \b from the regstring="(\bwatch\b)"
|
//workaround ,remove \b from the regstring="(\bwatch\b)"
|
||||||
regString.remove( QRegularExpression( "\\\\b" ) );
|
regString.remove( QRegularExpression( R"(\b)" ) );
|
||||||
|
|
||||||
//webengine support diacritic text searching.
|
//make it simple ,and do not support too much complex cases. such as wildcard etc.
|
||||||
auto parts = regString.split( " ", Qt::SkipEmptyParts );
|
firstAvailableText = regString;
|
||||||
//get first part of string.
|
|
||||||
for ( auto const & p : parts ) {
|
|
||||||
if ( p.startsWith( "-" ) )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
firstAvailableText = p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( firstAvailableText.isEmpty() ) {
|
if ( firstAvailableText.isEmpty() ) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -325,6 +325,8 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
|
||||||
ui.allowZim->setChecked( !p.fts.disabledTypes.contains( "ZIM", Qt::CaseInsensitive ) );
|
ui.allowZim->setChecked( !p.fts.disabledTypes.contains( "ZIM", Qt::CaseInsensitive ) );
|
||||||
ui.allowEpwing->setChecked( !p.fts.disabledTypes.contains( "EPWING", Qt::CaseInsensitive ) );
|
ui.allowEpwing->setChecked( !p.fts.disabledTypes.contains( "EPWING", Qt::CaseInsensitive ) );
|
||||||
ui.allowGls->setChecked( !p.fts.disabledTypes.contains( "GLS", Qt::CaseInsensitive ) );
|
ui.allowGls->setChecked( !p.fts.disabledTypes.contains( "GLS", Qt::CaseInsensitive ) );
|
||||||
|
|
||||||
|
ui.enablePosition->setChecked( p.fts.enablePosition );
|
||||||
#ifndef MAKE_ZIM_SUPPORT
|
#ifndef MAKE_ZIM_SUPPORT
|
||||||
ui.allowZim->hide();
|
ui.allowZim->hide();
|
||||||
ui.allowSlob->hide();
|
ui.allowSlob->hide();
|
||||||
|
|
|
@ -1268,20 +1268,6 @@ download page.</string>
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_4">
|
<layout class="QGridLayout" name="gridLayout_4">
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QCheckBox" name="allowAard">
|
|
||||||
<property name="text">
|
|
||||||
<string notr="true">Aard</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QCheckBox" name="allowBGL">
|
|
||||||
<property name="text">
|
|
||||||
<string notr="true">BGL</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QCheckBox" name="allowDictD">
|
<widget class="QCheckBox" name="allowDictD">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -1289,41 +1275,6 @@ download page.</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0">
|
|
||||||
<widget class="QCheckBox" name="allowDSL">
|
|
||||||
<property name="text">
|
|
||||||
<string notr="true">DSL</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="0">
|
|
||||||
<widget class="QCheckBox" name="allowMDict">
|
|
||||||
<property name="text">
|
|
||||||
<string notr="true">MDict</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="0">
|
|
||||||
<widget class="QCheckBox" name="allowSDict">
|
|
||||||
<property name="text">
|
|
||||||
<string notr="true">SDict</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QCheckBox" name="allowSlob">
|
|
||||||
<property name="text">
|
|
||||||
<string notr="true">Slob</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QCheckBox" name="allowStardict">
|
|
||||||
<property name="text">
|
|
||||||
<string notr="true">Stardict</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QCheckBox" name="allowXDXF">
|
<widget class="QCheckBox" name="allowXDXF">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -1331,17 +1282,10 @@ download page.</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QCheckBox" name="allowZim">
|
<widget class="QCheckBox" name="allowSlob">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string notr="true">Zim</string>
|
<string notr="true">Slob</string>
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="1">
|
|
||||||
<widget class="QCheckBox" name="allowEpwing">
|
|
||||||
<property name="text">
|
|
||||||
<string notr="true">Epwing</string>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -1352,7 +1296,73 @@ download page.</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="0" colspan="2">
|
<item row="7" column="0">
|
||||||
|
<widget class="QCheckBox" name="enablePosition">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Applies only to new incoming dictionaries.</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Enable positional information in the fulltext</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QCheckBox" name="allowAard">
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">Aard</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="1">
|
||||||
|
<widget class="QCheckBox" name="allowEpwing">
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">Epwing</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="0">
|
||||||
|
<widget class="QCheckBox" name="allowMDict">
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">MDict</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QCheckBox" name="allowZim">
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">Zim</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QCheckBox" name="allowStardict">
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">Stardict</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
|
<widget class="QCheckBox" name="allowDSL">
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">DSL</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QCheckBox" name="allowBGL">
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">BGL</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="5" column="0">
|
||||||
|
<widget class="QCheckBox" name="allowSDict">
|
||||||
|
<property name="text">
|
||||||
|
<string notr="true">SDict</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="6" column="0">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_14">
|
<layout class="QHBoxLayout" name="horizontalLayout_14">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_14">
|
<widget class="QLabel" name="label_14">
|
||||||
|
|
Loading…
Reference in a new issue