Kiwi Chris Posted December 23, 2020 Share Posted December 23, 2020 Currently, FieldtypeTextarea and FieldtypeText automatically have a fulltext index created on the field content, however there may be scenarios where this has an undesirable impact on performance and storage if the content of the field will never be searched, ie a field will only ever be accessed as a result of selectors using other fields on templates where it occurs. An example where I experienced an issue with the default behaviour was a module that stored a log of data import to a FieldtypeTextarea field, which grew quite long when importing thousands of records. The fulltext index of course indexed the content of this field, although it was unnecessary, resulting in a very large index file. What would be useful, would be an option (maybe a checkbox) when creating a field with one of these fieldtypes to disable indexing. This would mean the default behaviour would remain with the field indexed as usual, however if the field is never going to be used in selectors, checking the box would drop any fulltext or ordinary index, providing performance benefits. Obviously there needs to be a warning associated with checking this option that the field will no longer be able to be found using selectors, and unchecking the option subsequently should create the index(es) if required. Link to comment Share on other sites More sharing options...
BitPoet Posted December 23, 2020 Share Posted December 23, 2020 I'm not sure if this requirement is common enough it that will be considered for the core, but you can easily extend those Fieldtypes by yourself. These are untested, but they should work. It should even be possible to switch an existing FieldtypeText or FieldtypeTextarea to a non-indexed type.: FieldtypeTextNoindex <?php namespace ProcessWire; /** * ProcessWire Text Fieldtype without Index * * Fieldtype equivalent to FieldtypeText but * without creating an index on its text content * to preserve storage. * * Only use this Fieldtype if you will never search * through the contents of the field. * */ class FieldtypeTextNoindex extends FieldtypeText { public static function getModuleInfo() { return array( 'title' => 'Text Noindex', 'version' => "0.0.1", 'summary' => 'Field that stores a single line of text, not indexed' ); } /** * Return the database schema in specified format * * @param Field $field * @return array * */ public function getDatabaseSchema(Field $field) { $schema = parent::getDatabaseSchema($field); unset($schema['keys']['data_exact']); unset($schema['keys']['data']); return $schema; } } FieldtypeTextareaNoindex <?php namespace ProcessWire; /** * ProcessWire Textarea Fieldtype without Index * * Stores a large block of multi-line text like * FieldtypeTextarea but without an index on its * text content to save storage space. * * Only use this Fieldtype if you will never search * through the contents of the field. * */ class FieldtypeTextareaNoindex extends FieldtypeTextarea { public static function getModuleInfo() { return array( 'title' => 'Textarea Noindex', 'version' => "0.0.1", 'summary' => 'Filed that stores multiple lines of text, not indexed', 'permanent' => true, ); } /** * Get database schema used by the Field * * @param Field $field * @return array * */ public function getDatabaseSchema(Field $field) { $schema = parent::getDatabaseSchema($field); unset($schema['keys']['data_exact']); unset($schema['keys']['data']); return $schema; } } 7 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now