Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prioritize the manual set full text index option per dictionary #1730

Merged
merged 7 commits into from
Aug 21, 2024
9 changes: 7 additions & 2 deletions src/dict/aard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,13 @@ class AardDictionary: public BtreeIndexing::BtreeDictionary

void setFTSParameters( Config::FullTextSearch const & fts ) override
{
can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "AARD", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( enable_FTS.has_value() ) {
can_FTS = fts.enabled && enable_FTS.value();
}
else {
can_FTS = fts.enabled && !fts.disabledTypes.contains( "AARD", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}
}

protected:
Expand Down
8 changes: 6 additions & 2 deletions src/dict/bgl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,12 @@ class BglDictionary: public BtreeIndexing::BtreeDictionary

void setFTSParameters( Config::FullTextSearch const & fts ) override
{
can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "BGL", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( enable_FTS.has_value() ) {
can_FTS = fts.enabled && enable_FTS.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "BGL", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}

protected:
Expand Down
8 changes: 6 additions & 2 deletions src/dict/dictdfiles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ class DictdDictionary: public BtreeIndexing::BtreeDictionary

void setFTSParameters( Config::FullTextSearch const & fts ) override
{
can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "DICTD", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( enable_FTS.has_value() ) {
can_FTS = fts.enabled && enable_FTS.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "DICTD", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/dict/dictionary.hh
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ protected:
bool synonymSearchEnabled;
string dictionaryName;
//default to true;
bool enable_FTS = true;
std::optional< bool > enable_FTS;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment is wrong now. It should be changed to "The enable_fts option in metadata.toml"

I think enable_FTS should be renamed to metadata_enable_FTS.

As of now, the 3 variables

  • can_FTS
  • fts.enabled
  • enable_FTS

have no obvious difference.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To properly initialize std::optional< bool > metadata_enable_FTS = std::nullopt


// Load user icon if it exist
// By default set icon to empty
Expand Down
9 changes: 6 additions & 3 deletions src/dict/dsl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,12 @@ class DslDictionary: public BtreeIndexing::BtreeDictionary
{
if ( ensureInitDone().size() )
return;

can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "DSL", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( enable_FTS.has_value() ) {
can_FTS = fts.enabled && enable_FTS.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "DSL", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}

uint32_t getFtsIndexVersion() override
Expand Down
9 changes: 6 additions & 3 deletions src/dict/epwing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,12 @@ class EpwingDictionary: public BtreeIndexing::BtreeDictionary
{
if ( ensureInitDone().size() )
return;

can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "EPWING", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( enable_FTS.has_value() ) {
can_FTS = fts.enabled && enable_FTS.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "EPWING", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}

static int japaneseWriting( gd::wchar ch );
Expand Down
8 changes: 6 additions & 2 deletions src/dict/gls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,12 @@ class GlsDictionary: public BtreeIndexing::BtreeDictionary

void setFTSParameters( Config::FullTextSearch const & fts ) override
{
can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "GLS", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( enable_FTS.has_value() ) {
can_FTS = fts.enabled && enable_FTS.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "GLS", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}

protected:
Expand Down
9 changes: 6 additions & 3 deletions src/dict/mdx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,12 @@ class MdxDictionary: public BtreeIndexing::BtreeDictionary
{
if ( !ensureInitDone().empty() )
return;

can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "MDICT", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( enable_FTS.has_value() ) {
can_FTS = fts.enabled && enable_FTS.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "MDICT", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}

QString getCachedFileName( QString name );
Expand Down
8 changes: 6 additions & 2 deletions src/dict/sdict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,12 @@ class SdictDictionary: public BtreeIndexing::BtreeDictionary

void setFTSParameters( Config::FullTextSearch const & fts ) override
{
can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "SDICT", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( enable_FTS.has_value() ) {
can_FTS = fts.enabled && enable_FTS.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "SDICT", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}

protected:
Expand Down
8 changes: 6 additions & 2 deletions src/dict/slob.cc
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,12 @@ class SlobDictionary: public BtreeIndexing::BtreeDictionary

void setFTSParameters( Config::FullTextSearch const & fts ) override
{
can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "SLOB", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( enable_FTS.has_value() ) {
can_FTS = fts.enabled && enable_FTS.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "SLOB", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}

uint32_t getFtsIndexVersion() override
Expand Down
8 changes: 6 additions & 2 deletions src/dict/stardict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,12 @@ class StardictDictionary: public BtreeIndexing::BtreeDictionary

void setFTSParameters( Config::FullTextSearch const & fts ) override
{
can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "STARDICT", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( enable_FTS.has_value() ) {
can_FTS = fts.enabled && enable_FTS.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "STARDICT", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}

protected:
Expand Down
8 changes: 6 additions & 2 deletions src/dict/xdxf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,12 @@ class XdxfDictionary: public BtreeIndexing::BtreeDictionary

void setFTSParameters( Config::FullTextSearch const & fts ) override
{
can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "XDXF", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( enable_FTS.has_value() ) {
can_FTS = fts.enabled && enable_FTS.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "XDXF", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}

uint32_t getFtsIndexVersion() override
Expand Down
8 changes: 6 additions & 2 deletions src/dict/zim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,12 @@ class ZimDictionary: public BtreeIndexing::BtreeDictionary

void setFTSParameters( Config::FullTextSearch const & fts ) override
{
can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "ZIM", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
if ( enable_FTS.has_value() ) {
can_FTS = fts.enabled && enable_FTS.value();
}
else
can_FTS = fts.enabled && !fts.disabledTypes.contains( "ZIM", Qt::CaseInsensitive )
&& ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize );
}

protected:
Expand Down
Loading