diff --git a/icons/fts_disabled.svg b/icons/fts_disabled.svg new file mode 100644 index 00000000..b3b8a224 --- /dev/null +++ b/icons/fts_disabled.svg @@ -0,0 +1,63 @@ + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/icons/fts_enabled.svg b/icons/fts_enabled.svg new file mode 100644 index 00000000..923d7ebf --- /dev/null +++ b/icons/fts_enabled.svg @@ -0,0 +1,63 @@ + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/resources.qrc b/resources.qrc index 0171ab46..3de960bb 100644 --- a/resources.qrc +++ b/resources.qrc @@ -92,5 +92,7 @@ icons/old-downarrow.png icons/custom_trans.svg icons/splash.png + icons/fts_disabled.svg + icons/fts_enabled.svg diff --git a/src/dict/aard.cc b/src/dict/aard.cc index aacbd652..c16dbac7 100644 --- a/src/dict/aard.cc +++ b/src/dict/aard.cc @@ -263,7 +263,7 @@ public: void setFTSParameters( Config::FullTextSearch const & fts ) override { - can_FTS = fts.enabled && !fts.disabledTypes.contains( "AARD", Qt::CaseInsensitive ) + can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "AARD", Qt::CaseInsensitive ) && ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize ); } diff --git a/src/dict/bgl.cc b/src/dict/bgl.cc index c7ff379e..0894b4d8 100644 --- a/src/dict/bgl.cc +++ b/src/dict/bgl.cc @@ -225,7 +225,7 @@ public: void setFTSParameters( Config::FullTextSearch const & fts ) override { - can_FTS = fts.enabled && !fts.disabledTypes.contains( "BGL", Qt::CaseInsensitive ) + can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "BGL", Qt::CaseInsensitive ) && ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize ); } diff --git a/src/dict/dictdfiles.cc b/src/dict/dictdfiles.cc index 01db2de0..4d2f3e80 100644 --- a/src/dict/dictdfiles.cc +++ b/src/dict/dictdfiles.cc @@ -140,7 +140,7 @@ public: void setFTSParameters( Config::FullTextSearch const & fts ) override { - can_FTS = fts.enabled && !fts.disabledTypes.contains( "DICTD", Qt::CaseInsensitive ) + can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "DICTD", Qt::CaseInsensitive ) && ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize ); } }; diff --git a/src/dict/dictionary.hh b/src/dict/dictionary.hh index 5fc4b646..aa6b6373 100644 --- a/src/dict/dictionary.hh +++ b/src/dict/dictionary.hh @@ -312,6 +312,8 @@ protected: QAtomicInt FTS_index_completed; bool synonymSearchEnabled; string dictionaryName; + //default to true; + bool enable_FTS = true; // Load user icon if it exist // By default set icon to empty @@ -369,6 +371,11 @@ public: dictionaryName = _dictionaryName; } + void setFtsEnable( bool _enable_FTS ) + { + enable_FTS = _enable_FTS; + } + /// Returns all the available properties, like the author's name, copyright, /// description etc. All strings are in utf8. virtual map< Property, string > getProperties() noexcept = 0; diff --git a/src/dict/dsl.cc b/src/dict/dsl.cc index 575295a4..221f9744 100644 --- a/src/dict/dsl.cc +++ b/src/dict/dsl.cc @@ -240,7 +240,7 @@ public: if ( ensureInitDone().size() ) return; - can_FTS = fts.enabled && !fts.disabledTypes.contains( "DSL", Qt::CaseInsensitive ) + can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "DSL", Qt::CaseInsensitive ) && ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize ); } diff --git a/src/dict/epwing.cc b/src/dict/epwing.cc index da8b5c7b..34d0ef39 100644 --- a/src/dict/epwing.cc +++ b/src/dict/epwing.cc @@ -155,7 +155,7 @@ public: if ( ensureInitDone().size() ) return; - can_FTS = fts.enabled && !fts.disabledTypes.contains( "EPWING", Qt::CaseInsensitive ) + can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "EPWING", Qt::CaseInsensitive ) && ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize ); } diff --git a/src/dict/gls.cc b/src/dict/gls.cc index 0b63817c..d3e10665 100644 --- a/src/dict/gls.cc +++ b/src/dict/gls.cc @@ -408,7 +408,7 @@ public: void setFTSParameters( Config::FullTextSearch const & fts ) override { - can_FTS = fts.enabled && !fts.disabledTypes.contains( "GLS", Qt::CaseInsensitive ) + can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "GLS", Qt::CaseInsensitive ) && ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize ); } diff --git a/src/dict/loaddictionaries.cc b/src/dict/loaddictionaries.cc index d32d3a02..53eebbf4 100644 --- a/src/dict/loaddictionaries.cc +++ b/src/dict/loaddictionaries.cc @@ -177,6 +177,9 @@ void LoadDictionaries::handlePath( Config::Path const & path ) if ( dictMetaData && dictMetaData->name ) { dict->setName( dictMetaData->name.value() ); } + if ( dictMetaData && dictMetaData->fullindex ) { + dict->setFtsEnable( dictMetaData->fullindex.value() ); + } } } diff --git a/src/dict/mdx.cc b/src/dict/mdx.cc index a80a1d1a..322272f6 100644 --- a/src/dict/mdx.cc +++ b/src/dict/mdx.cc @@ -261,7 +261,7 @@ public: if ( !ensureInitDone().empty() ) return; - can_FTS = fts.enabled && !fts.disabledTypes.contains( "MDICT", Qt::CaseInsensitive ) + can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "MDICT", Qt::CaseInsensitive ) && ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize ); } diff --git a/src/dict/sdict.cc b/src/dict/sdict.cc index 67eb7116..24d1a249 100644 --- a/src/dict/sdict.cc +++ b/src/dict/sdict.cc @@ -177,7 +177,7 @@ public: void setFTSParameters( Config::FullTextSearch const & fts ) override { - can_FTS = fts.enabled && !fts.disabledTypes.contains( "SDICT", Qt::CaseInsensitive ) + can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "SDICT", Qt::CaseInsensitive ) && ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize ); } diff --git a/src/dict/slob.cc b/src/dict/slob.cc index 1f86c41f..8ef08b3d 100644 --- a/src/dict/slob.cc +++ b/src/dict/slob.cc @@ -640,7 +640,7 @@ public: void setFTSParameters( Config::FullTextSearch const & fts ) override { - can_FTS = fts.enabled && !fts.disabledTypes.contains( "SLOB", Qt::CaseInsensitive ) + can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "SLOB", Qt::CaseInsensitive ) && ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize ); } diff --git a/src/dict/stardict.cc b/src/dict/stardict.cc index bd07a618..3028ba16 100644 --- a/src/dict/stardict.cc +++ b/src/dict/stardict.cc @@ -205,7 +205,7 @@ public: void setFTSParameters( Config::FullTextSearch const & fts ) override { - can_FTS = fts.enabled && !fts.disabledTypes.contains( "STARDICT", Qt::CaseInsensitive ) + can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "STARDICT", Qt::CaseInsensitive ) && ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize ); } diff --git a/src/dict/xdxf.cc b/src/dict/xdxf.cc index 076c6898..de640fde 100644 --- a/src/dict/xdxf.cc +++ b/src/dict/xdxf.cc @@ -203,7 +203,7 @@ public: void setFTSParameters( Config::FullTextSearch const & fts ) override { - can_FTS = fts.enabled && !fts.disabledTypes.contains( "XDXF", Qt::CaseInsensitive ) + can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "XDXF", Qt::CaseInsensitive ) && ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize ); } diff --git a/src/dict/zim.cc b/src/dict/zim.cc index 83ea80e3..d4288628 100644 --- a/src/dict/zim.cc +++ b/src/dict/zim.cc @@ -221,7 +221,7 @@ public: void setFTSParameters( Config::FullTextSearch const & fts ) override { - can_FTS = fts.enabled && !fts.disabledTypes.contains( "ZIM", Qt::CaseInsensitive ) + can_FTS = enable_FTS && fts.enabled && !fts.disabledTypes.contains( "ZIM", Qt::CaseInsensitive ) && ( fts.maxDictionarySize == 0 || getArticleCount() <= fts.maxDictionarySize ); } diff --git a/src/metadata.cc b/src/metadata.cc index 3a8b86b8..582a9d82 100644 --- a/src/metadata.cc +++ b/src/metadata.cc @@ -34,5 +34,19 @@ std::optional< Metadata::result > Metadata::load( std::string_view filepath ) } result.name = tbl[ "metadata" ][ "name" ].value_exact< std::string >(); + + const auto fullindex = tbl[ "fts" ]; + if ( fullindex.as_string() ) { + const auto value = fullindex.as_string()->get(); + result.fullindex = value == "1" || value == "on" || value == "true"; + } + else if ( fullindex.as_boolean() ) { + auto value = fullindex.as_boolean()->get(); + result.fullindex = value; + } + else if ( fullindex.as_integer() ) { + const auto value = fullindex.as_integer()->get(); + result.fullindex = value > 0; + } return result; } diff --git a/src/metadata.hh b/src/metadata.hh index 5605dfe9..a8637a41 100644 --- a/src/metadata.hh +++ b/src/metadata.hh @@ -12,6 +12,7 @@ struct result { std::optional< std::vector< std::string > > categories; std::optional< std::string > name; + std::optional< bool > fullindex; }; [[nodiscard]] std::optional< Metadata::result > load( std::string_view filepath ); diff --git a/src/ui/dictinfo.cc b/src/ui/dictinfo.cc index cdfac39c..73b06cf6 100644 --- a/src/ui/dictinfo.cc +++ b/src/ui/dictinfo.cc @@ -20,6 +20,7 @@ void DictInfo::showInfo( sptr< Dictionary::Class > dict ) setWindowTitle( QString::fromUtf8( dict->getName().data(), dict->getName().size() ) ); ui.dictionaryId->setText( QString::fromStdString( dict->getId() ) ); + ui.enableFullindex->setText( dict->canFTS() ? tr( "Full-text search enabled" ) : tr( "Full-text search disabled" ) ); ui.dictionaryTotalArticles->setText( QString::number( dict->getArticleCount() ) ); ui.dictionaryTotalWords->setText( QString::number( dict->getWordCount() ) ); ui.dictionaryTranslatesFrom->setText( Language::localizedStringForId( dict->getLangFrom() ) ); diff --git a/src/ui/dictinfo.ui b/src/ui/dictinfo.ui index bb01984b..1e73f5dd 100644 --- a/src/ui/dictinfo.ui +++ b/src/ui/dictinfo.ui @@ -23,68 +23,6 @@ - - - - - - - Qt::AlignCenter - - - - - - - Total words: - - - - - - - Translates from: - - - - - - - - - - - - - - - - - Qt::AlignCenter - - - - - - - - - - - - - - Total articles: - - - - - - - Open folder - - - @@ -95,17 +33,24 @@ - - + + - Translates to: + - - + + - Index filename: + + + + + + + + Open index folder @@ -119,10 +64,72 @@ - - + + - Open index folder + + + + Qt::AlignCenter + + + + + + + Total articles: + + + + + + + Index filename: + + + + + + + Total words: + + + + + + + Open folder + + + + + + + + + + Qt::AlignCenter + + + + + + + Translates from: + + + + + + + + + + + + + + Translates to: diff --git a/website/docs/custom_dictionary_name.md b/website/docs/custom_dictionary.md similarity index 53% rename from website/docs/custom_dictionary_name.md rename to website/docs/custom_dictionary.md index 6db3b23b..6b984a79 100644 --- a/website/docs/custom_dictionary_name.md +++ b/website/docs/custom_dictionary.md @@ -1,7 +1,13 @@ -You can customize the dictionary name by the metadata.toml which is also used in [metadata grouping](manage_groups.md) +You can customize the dictionary by the metadata.toml which is also used in [metadata grouping](manage_groups.md) ## About the configuration of metadata.toml + + +the metadata.toml use toml format for configuration. + +## Customize the name of the dictionary + ```toml [metadata] name = "New Name" @@ -32,3 +38,24 @@ For example, ``` +## Disable full-text search for certain dictionary + +```toml +fts=false + +[metadata] +name="New Name" + +``` + +this `fts` field's value can be on/off, 1/0 ,true/false etc. + +``` +fts=false +``` +will disable the current dictionary's full-text search. + + +you can check the full-text search on each dictionary's info dialog. + +![](img/dictionary-info-fullindex.png) \ No newline at end of file diff --git a/website/docs/img/dictionary-info-fullindex.png b/website/docs/img/dictionary-info-fullindex.png new file mode 100644 index 00000000..2bece5f3 Binary files /dev/null and b/website/docs/img/dictionary-info-fullindex.png differ diff --git a/website/mkdocs.yml b/website/mkdocs.yml index 547949cb..98a13ef6 100644 --- a/website/mkdocs.yml +++ b/website/mkdocs.yml @@ -42,7 +42,7 @@ nav: - Custom Stylesheet & JavaScript: topic_userstyle.md - Portable Mode: topic_portablemode.md - Custom transliteration: topic_transliteration.md - - Customize Dictionary Name: custom_dictionary_name.md + - Customize Dictionary: custom_dictionary.md - OCR Integration: howto/ocr.md - Report Bugs & Feedbacks: feedbacks.md - Contributor Guides: