Site search with tag filtering

Silverstripe Version: 4.3.2

I am trying to enable search on a site but for the life of me I have been unsuccessful in doing so.

I would like to have a site wide search but also be able to filter the results by tags and category. I can’t even get the search to work :slightly_smiling_face:

I used the tutorial in the lessons (https://www.silverstripe.org/learn/lessons/v4/working-with-data-relationships-has-many-1) which does show results but doesn’t seem to priorities search terms and seems to be more focused on the filtering part of searching.

I have also tried to enable FulltextSearchable, but when I place

SilverStripe\ORM\Search\FulltextSearchable::enable();

in my _config.php I receive the following error

error-log.ERROR: Uncaught Exception TypeError: "Argument 1 passed to SilverStripe\Config\MergeStrategy\Priority::mergeArray() must be of the type array, string given, called in /.../vendor/silverstripe/framework/src/Core/Config/Middleware/InheritanceMiddleware.php on line 43" at /.../vendor/silverstripe/config/src/MergeStrategy/Priority.php line 59 {"exception":"[object] (TypeError(code: 0): Argument 1 passed to SilverStripe\\Config\\MergeStrategy\\Priority::mergeArray() must be of the type array, string given, called in /.../vendor/silverstripe/framework/src/Core/Config/Middleware/InheritanceMiddleware.php on line 43 at /.../vendor/silverstripe/config/src/MergeStrategy/Priority.php:59)"} []

I am pretty sure this is due to me installing silverstripe/silverstripe-fulltextsearch. I have tried to remove silverstripe-fulltextsearch with

composer remove silverstripe/fulltextsearch && vendore/bin/fulltextsearch_quickstart

but when I run a dev/build after removing fulltextsearch I recieve the following error

error-log.ALERT: Fatal Error (E_ERROR): Uncaught InvalidArgumentException: SilverStripe\ORM\DataObject references nonexistent SilverStripe\FullTextSearch\Search\Extensions\SearchUpdater_ObjectHandler in 'extensions' in /.../vendor/silverstripe/framework/src/Core/Config/Middleware/ExtensionMiddleware.php:70 Stack trace: #0 /.../vendor/silverstripe/framework/src/Core/Config/Middleware/ExtensionMiddleware.php(41): SilverStripe\Core\Config\Middleware\ExtensionMiddleware->getExtraConfig('SilverStripe\\OR...', Array, 0) #1 /.../vendor/silverstripe/config/src/Middleware/MiddlewareAware.php(56): SilverStripe\Core\Config\Middleware\ExtensionMiddleware->getClassConfig('SilverStripe\\OR...', 0, Object(Closure)) #2 /.../vendor/silverstripe/framework/src/Core/Config/Middleware/InheritanceMiddleware.php(30): SilverStripe\Config\Collections\MemoryConfigCollection {"code":1,"message":"Uncaught InvalidArgumentException: SilverStripe\\ORM\\DataObject references nonexistent SilverStripe\\FullTextSearch\\Search\\Extensions\\SearchUpdater_ObjectHandler in 'extensions' in /.../vendor/silverstripe/framework/src/Core/Config/Middleware/ExtensionMiddleware.php:70\nStack trace:\n#0 /.../vendor/silverstripe/framework/src/Core/Config/Middleware/ExtensionMiddleware.php(41): SilverStripe\\Core\\Config\\Middleware\\ExtensionMiddleware->getExtraConfig('SilverStripe\\\\OR...', Array, 0)\n#1 /.../vendor/silverstripe/config/src/Middleware/MiddlewareAware.php(56): SilverStripe\\Core\\Config\\Middleware\\ExtensionMiddleware->getClassConfig('SilverStripe\\\\OR...', 0, Object(Closure))\n#2 /.../vendor/silverstripe/framework/src/Core/Config/Middleware/InheritanceMiddleware.php(30): SilverStripe\\Config\\Collections\\MemoryConfigCollection","file":"/.../vendor/silverstripe/framework/src/Core/Config/Middleware/ExtensionMiddleware.php","line":70,"trace":null} []

I do have Solr installed on my system but I don’t seem to be able to access it. It is a VPS running WHM and cPanel if that helps.

I have also tried the following addons ‘jaedb/search’, axllent/silverstripe-ftsearch and nglasl/silverstripe-extensible-search but can’t seem to get them going, although this is probably due to me not understanding the documentation properly, as I am not a programmer, so have probably placed things in the wrong files.

If someone has successfully enabled a search on their site can you please explain how you did it, which files you modified and the basic code you used?

Essentially, what I am trying to do is have a search form in the header of my site which goes to a results page that displays the results of the search. I also have a separate search form on the homepage that has an advanced search option to filter the pages by Tags (using silverstripe/silverstripe-tagfield) and by some categories (which are selected in the admin section using a simple dropdown field).

Documentation for a search feature seems to be lacking for SilverStripe 4, hopefully this thread can be of assistance for other people in the same situation as me. If I work something out I will definetly post it back here.

1 Like

Hi FrankenBunt, Hi all SilverstripeSearchSpecialists

did you solve your issue? I’m currently working with SS4.10 and tried to get the fulltextsearch started with silverstripe/silverstripe-fulltextsearch, without success.

I got Solr up and running (downgraded from v8 to v5) with some bugfixes to schema.xml and solrconfig.xml and be currently able to update and query sample-data in the instance gettingstarted included in Solr. Therefore I think Solr is ready - it runs as single docker-container.

I extended the SolrIndex (SearchIndex extends SolrIndex) and added a DataObject ($this->addClass(Article::class);) including a field ($this->addFulltextField('Title');).

I ran the both tasks dev/tasks/Solr_Configure and dev/tasks/Solr_Reindex. I did not get errors in verbose mode, but some curios message
[2023-03-17 22:03:40] silverstripe\fulltextsearch\solr\tasks\solr_reindex.INFO: Silverstripe Framework requires a "database" key in DB::getConfig(). Did you forget to set SS_DATABASE_NAME or SS_DATABASE_CHOOSE_NAME in your environment? [] []
My Silver4 is up and running in docker with all DB-parameters set as environment variables in docker-compose.xml. I did not understand this message. Copying the variables to Solr-docker-compose.yml did not change anything.

If I update an Article-DataObject, I see in Solr-Logs the deletion
o.a.s.u.p.LogUpdateProcessorFactory [SearchIndex] webapp=/solr path=/update params={wt=json}{delete=[2-Article-{"SilverStripe\\FullTextSe...
but no update. If i create a new Article, the log-result is the same. If i query in Solr-SearchIndex all documents q=*:* I get no results.

I have no glue why (obviuosly) the Reindex won´t work in case that an update is sent to Solr and results in deletion of the old record. Did i missed anything? Does anybody has an idea or could help me with Solr?

Best regards
chrclaus

Is it possible, that the re-index task is not doing the full part? In the task-output, there is only a clearing-task Clearing obsolete classes logged and no update with current data-objects alreday existing.

`Running Task SilverStripe\FullTextSearch\Solr\Tasks\Solr_Reindex

[2023-03-18 17:53:34] silverstripe\fulltextsearch\solr\tasks\solr_reindex.INFO: Clearing obsolete classes from DefaultIndex

[2023-03-18 17:53:34] silverstripe\fulltextsearch\solr\tasks\solr_reindex.INFO: Running php /var/www/html/vendor/silverstripe/framework/cli-script.php dev/tasks/Solr_Reindex index=DefaultIndex class=SilverStripe\CMS\Model\SiteTree group=0 groups=1 variantstate={“SilverStripe\FullTextSearch\Search\Variants\SearchVariantVersioned”:“Live”} verbose=1

[2023-03-18 17:53:35] silverstripe\fulltextsearch\solr\tasks\solr_reindex.INFO: Silverstripe Framework requires a “database” key in DB::getConfig(). Did you forget to set SS_DATABASE_NAME or SS_DATABASE_CHOOSE_NAME in your environment?

[2023-03-18 17:53:35] silverstripe\fulltextsearch\solr\tasks\solr_reindex.INFO: Clearing obsolete classes from SearchIndex

[2023-03-18 17:53:35] silverstripe\fulltextsearch\solr\tasks\solr_reindex.INFO: Running php /var/www/html/vendor/silverstripe/framework/cli-script.php dev/tasks/Solr_Reindex index=SearchIndex class=Article group=0 groups=1 variantstate={“SilverStripe\FullTextSearch\Search\Variants\SearchVariantVersioned”:“Live”} verbose=1

[2023-03-18 17:53:35] silverstripe\fulltextsearch\solr\tasks\solr_reindex.INFO: Silverstripe Framework requires a “database” key in DB::getConfig(). Did you forget to set SS_DATABASE_NAME or SS_DATABASE_CHOOSE_NAME in your environment?

[2023-03-18 17:53:35] silverstripe\fulltextsearch\solr\tasks\solr_reindex.INFO: Running php /var/www/html/vendor/silverstripe/framework/cli-script.php dev/tasks/Solr_Reindex index=SearchIndex class=SilverStripe\CMS\Model\SiteTree group=0 groups=1 variantstate={“SilverStripe\FullTextSearch\Search\Variants\SearchVariantVersioned”:“Live”} verbose=1

[2023-03-18 17:53:35] silverstripe\fulltextsearch\solr\tasks\solr_reindex.INFO: Silverstripe Framework requires a “database” key in DB::getConfig(). Did you forget to set SS_DATABASE_NAME or SS_DATABASE_CHOOSE_NAME in your environment?

[2023-03-18 17:53:35] silverstripe\fulltextsearch\solr\tasks\solr_reindex.INFO: Running php /var/www/html/vendor/silverstripe/framework/cli-script.php dev/tasks/Solr_Reindex index=SearchIndex class=Person group=0 groups=1 variantstate= verbose=1

[2023-03-18 17:53:35] silverstripe\fulltextsearch\solr\tasks\solr_reindex.INFO: Silverstripe Framework requires a “database” key in DB::getConfig(). Did you forget to set SS_DATABASE_NAME or SS_DATABASE_CHOOSE_NAME in your environment?

[2023-03-18 17:53:35] silverstripe\fulltextsearch\solr\tasks\solr_reindex.INFO: Clearing obsolete classes from DNADesign-Elemental-Search-ElementalSolrIndex

[2023-03-18 17:53:35] silverstripe\fulltextsearch\solr\tasks\solr_reindex.INFO: Running php /var/www/html/vendor/silverstripe/framework/cli-script.php dev/tasks/Solr_Reindex index=DNADesign\Elemental\Search\ElementalSolrIndex class=Page group=0 groups=1 variantstate={“SilverStripe\FullTextSearch\Search\Variants\SearchVariantVersioned”:“Live”} verbose=1

[2023-03-18 17:53:35] silverstripe\fulltextsearch\solr\tasks\solr_reindex.INFO: Silverstripe Framework requires a “database” key in DB::getConfig(). Did you forget to set SS_DATABASE_NAME or SS_DATABASE_CHOOSE_NAME in your environment? `

I struggled with the DB-config (i will open a new question) and with the canView-property of my dataobjects. I get the search up and runnning.

@chrclaus the fulltextsearch module is not compatible with solr 5, which you’ve indicated you’re using. I recommend using firesphere/solr-search which supports a much wider range of solr versions.

In any case, you are responding to a very old thread. Please create a new thread detailing the problems you are encountering in order to receive further help.

I noticed the compatibility statement for v3 and v4. Due to the fact, that I did not found a docker image in v4 I updated the solrconfig.xml. I changed the two deprecated classes to v5. Using the Solr4Service-class works also. For the moment everything works.

Thanks for your hint to old threads.