Site Search on Sitecore-4 (4.5) - How to enable it?

<%- if @topic_view.topic.tags.present? %>
<%= t 'js.tagging.tags' %>: <%- @topic_view.topic.tags.each do |t| %> <%= t %> <%- end %>
<% end %>

Using Silverstripe Version: 4.5 on both local server and online (for learning purposes).

I am a experienced Website administrator/Digital Marketeer/HTML/CSS but a newcomer to PHP and back-end development, and I am using this quarantine period to up-skill and learn new development skills related to CMS systems I usually manage from a front-end/designer/marketeer perspective.

I have created a Silvestripe website on my localserver and also on a webserver and so far really enjoying how easy is to use SS as a content user. I have also created other websites on other platforms during this lock-down period (namely Wordpress and Magento), and although I found Silverstripe one of the easiest to use so far, it’s by far the one with the smallest community and harder to find support when you have an issue. The forum here has many unanswered questions and stackoverflow also has plenty of unanswered answers.

Documentation also is not that extensive, which in this case I could only find documentation for the v3 version for the site search.

I am now stuck with implementing the site search for my personal project, I have managed to have the search box visible on the header, but nothing happens when I click on the search button and try to search for anything.

I have tried it on several themes, but currently trying to make it work on an amended version of Watea theme: https://italomaniacs.com/

I have also checked previous queries on this forum similar to mine, but none of them helped me (either not answered yet or too simple answer for my level of PHP):

My question would be, what is the simple way to implement a basic website search on a fresh installation of SS 4.x? No extra servers or third parties services just simple and basic site search using MYSQL.

Is there anyone out there that could help me out on giving me a hand and I am happy to support you back on other topics I have experience on.

I know I need to configure the following files, but I can’t figure out the exact setup (probably because of my lack on PHP coding) or because I am missing an extra module to go with the exact setup:
- /mysite/_config.php
/mysite/code/Page.php

Many thanks for anyone that could help me out on my quarantine lessons!

Caio

Apologies for not being clear in my question above, I tried to amend it but it’s against the rules, I also noticed I wrote Sitecore (which is de CMS I use on a daily basis on my work) as opposed to Silverstripe, which is the one I am trying to learn on my free time as a personal quarantine project.

Please, if you are a moderator, can you rename ‘Sitecore’ with ‘Silverstripe’ in the title? Thanks!

Clarifying and making it clearer my struggle was to enable the search form on Silverstripe 4.5.

I found plenty of documentation about it, however, the info needed is not in one place, therefore if you are not a experienced Silverstripe developer, it’s not that clear what you have to do on v4, so I hope my mini steps below can help other people as I spent hours myself :face_with_head_bandage: trying to figure this out, and by the amount of unanswered questions I found, it’s probably other people’s struggle too.

  • I am using a fresh installed version of Silverstripe 4.5 and the simple theme (composer create-project silverstripe/installer my-project).
  • No other Themes or add-ons installed

I used this Sitecore 3 tutorial (https://docs.silverstripe.org/en/3/tutorials/site_search) as a base for my research:

Step 1 on v3: Add the code below to mysite/_config.php

FulltextSearchable::enable();

Changes to v4?: After reading other similar queries in this forum (Site Search) and also in stackoverflow (full text search - Enable FullTextSearch in Silverstripe 4 - Stack Overflow), people’s answers pointed that on SS v4, one should add the code below instead:

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

This is how my app/_config.php file looks after adding the suggested line:

<?php

use SilverStripe\Security\PasswordValidator;

use SilverStripe\Security\Member;

// remove PasswordValidator for SilverStripe 5.0

$validator = PasswordValidator::create();

// Settings are registered via Injector configuration - see passwords.yml in framework

Member::set_password_validator($validator);

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

Step 2 on v3: add $SearchForm anywhere in the templates.

Changes to v4?: In SS4 the simple theme already contains this code in themes/simple/templates/Includes/Header.ss
This is how my Header.ss looks without any changes from a fresh install:

<header class="header" role="banner">
	<div class="inner">
		<div class="unit size4of4 lastUnit">
			<a href="$BaseHref" class="brand" rel="home">
				<h1>$SiteConfig.Title</h1>
				<% if $SiteConfig.Tagline %>
				<p>$SiteConfig.Tagline</p>
				<% end_if %>
			</a>
			<% if $SearchForm %>
				<span class="search-dropdown-icon">L</span>
				<div class="search-bar">
					$SearchForm
				</div>
			<% end_if %>
			<% include Navigation %>
		</div>
	</div>
</header>

According to the v3 Tutorial, that’s it, run dev/build?flush=all and the search field appears. However doing more research, for SS V4 there are extra steps needed.

Step 3 on V4: According to this answer (SS 4.0 Site Search - How to enable?) and this one (Silverstripe 4 - How do you enable FullTextSearchable and $SearchForm? - Stack Overflow), on SS v4 the extra step is to add the following code to the file src/Page.php:

    use SilverStripe\ORM\DataObject;
    use SilverStripe\ORM\Connect\MySQLSchemaManager;

    class MyDataObject extends DataObject
    {
        private static $create_table_options = [
            MySQLSchemaManager::ID => 'ENGINE=MyISAM'
        ];
    }

This is how my src/Page.php file looks after adding the suggested code:

<?php

namespace {

    use SilverStripe\CMS\Model\SiteTree;

    class Page extends SiteTree
    {
        private static $db = [];

        private static $has_one = [];
    }

    use SilverStripe\ORM\DataObject;
    use SilverStripe\ORM\Connect\MySQLSchemaManager;

    class MyDataObject extends DataObject
    {
        private static $create_table_options = [
            MySQLSchemaManager::ID => 'ENGINE=MyISAM'
        ];
    }
}

Now if you run dev/build?flush=all the search field should appear:

Other answers I found online suggested that changes were needed to the files below, however I didn’t need to make any changes to any other file to make the search field appear. It might be the case for other themes or modules, but not for a fresh installation with the simple theme:

  • app/_config/theme.yml
  • app/src/PageController.php

:smiley: