mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-12-03 15:34:06 +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() )
|
||||
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() )
|
||||
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" ) );
|
||||
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.appendChild( dd.createTextNode( QString::number( c.preferences.fts.maxDictionarySize ) ) );
|
||||
hd.appendChild( opt );
|
||||
|
|
|
@ -176,6 +176,8 @@ struct FullTextSearch
|
|||
int searchMode;
|
||||
bool enabled;
|
||||
|
||||
bool enablePosition = false;
|
||||
|
||||
quint32 maxDictionarySize;
|
||||
QByteArray dialogGeometry;
|
||||
QString disabledTypes;
|
||||
|
|
|
@ -240,7 +240,14 @@ void makeFTSIndex( BtreeIndexing::BtreeDictionary * dict, QAtomicInt & isCancell
|
|||
Xapian::Document doc;
|
||||
|
||||
indexer.set_document( doc );
|
||||
indexer.index_text_without_positions( articleStr.toStdString() );
|
||||
|
||||
if ( GlobalBroadcaster::instance()->getPreference()->fts.enablePosition ) {
|
||||
indexer.index_text( articleStr.toStdString() );
|
||||
}
|
||||
else {
|
||||
indexer.index_text_without_positions( articleStr.toStdString() );
|
||||
}
|
||||
|
||||
doc.set_data( std::to_string( address ) );
|
||||
// Add the document to the database.
|
||||
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.
|
||||
//whole word match regString will contain \b . can not match the above senario.
|
||||
//workaround ,remove \b from the regstring="(\bwatch\b)"
|
||||
regString.remove( QRegularExpression( "\\\\b" ) );
|
||||
regString.remove( QRegularExpression( R"(\b)" ) );
|
||||
|
||||
//webengine support diacritic text searching.
|
||||
auto parts = regString.split( " ", Qt::SkipEmptyParts );
|
||||
//get first part of string.
|
||||
for ( auto const & p : parts ) {
|
||||
if ( p.startsWith( "-" ) )
|
||||
continue;
|
||||
|
||||
firstAvailableText = p;
|
||||
break;
|
||||
}
|
||||
//make it simple ,and do not support too much complex cases. such as wildcard etc.
|
||||
firstAvailableText = regString;
|
||||
|
||||
if ( firstAvailableText.isEmpty() ) {
|
||||
return;
|
||||
|
|
|
@ -325,6 +325,8 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
|
|||
ui.allowZim->setChecked( !p.fts.disabledTypes.contains( "ZIM", Qt::CaseInsensitive ) );
|
||||
ui.allowEpwing->setChecked( !p.fts.disabledTypes.contains( "EPWING", Qt::CaseInsensitive ) );
|
||||
ui.allowGls->setChecked( !p.fts.disabledTypes.contains( "GLS", Qt::CaseInsensitive ) );
|
||||
|
||||
ui.enablePosition->setChecked( p.fts.enablePosition );
|
||||
#ifndef MAKE_ZIM_SUPPORT
|
||||
ui.allowZim->hide();
|
||||
ui.allowSlob->hide();
|
||||
|
|
|
@ -1268,20 +1268,6 @@ download page.</string>
|
|||
<bool>true</bool>
|
||||
</property>
|
||||
<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">
|
||||
<widget class="QCheckBox" name="allowDictD">
|
||||
<property name="text">
|
||||
|
@ -1289,41 +1275,6 @@ download page.</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="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">
|
||||
<widget class="QCheckBox" name="allowXDXF">
|
||||
<property name="text">
|
||||
|
@ -1331,17 +1282,10 @@ download page.</string>
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QCheckBox" name="allowZim">
|
||||
<item row="0" column="1">
|
||||
<widget class="QCheckBox" name="allowSlob">
|
||||
<property name="text">
|
||||
<string notr="true">Zim</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QCheckBox" name="allowEpwing">
|
||||
<property name="text">
|
||||
<string notr="true">Epwing</string>
|
||||
<string notr="true">Slob</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -1352,7 +1296,73 @@ download page.</string>
|
|||
</property>
|
||||
</widget>
|
||||
</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">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_14">
|
||||
|
|
Loading…
Reference in a new issue