Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

modify search engine

Go to End

2 Posts   1460 Views


Community Member, 181 Posts

21 December 2010 at 4:13am

Edited: 21/12/2010 4:19am


I'm tring to mofidy search engine to add other fields

I have "Product" page with fields: 'content' and 'technical information'

first i added Product to classesToSearch in SearchForm action

    function SearchForm() {

        $searchText = isset($this->Query) ? $this->Query : 'Znajd┼║ produkt';
        $fields = new FieldSet(
                        new TextField("Search", "", $searchText)
        $actions = new FieldSet(
                        new FormAction('results', 'szukaj')

        $form = new SearchForm($this, "SearchForm", $fields, $actions);
        $form->classesToSearch(array('SiteTree', 'Product'));

        return $form;

next modified SearchForm.php like that:

	 * Classes to search
	protected $classesToSearch = array("SiteTree", "Product", "File");

       function classesToSearch($classes) {
            $illegalClasses = array_diff($classes, array('SiteTree', 'Product', 'File'));
            $legalClasses = array_intersect($classes, array('SiteTree', 'Product', 'File'));

       public function searchEngine(..............) {
          $extraFilters = array('SiteTree' => '',  'Product'=>'', 'File' => '');

          if($keywords) {
              $match['Product'] = "MATCH (Content, TechnicalInformation) AGAINST ('$keywords') AND ClassName = 'Product'";
              $relevance['Product'] = "MATCH (Content, TechnicalInformation) AGAINST ('$relevanceKeywords' IN BOOLEAN MODE)";

 	  // Generate initial queries and base table names
	  $baseClasses = array('SiteTree' => '', 'Product'=>'', 'File' => '');

          foreach($this->classesToSearch as $class) {
              $baseClasses['Product'] = '`Product_live`';

 	  // Make column selection lists
 	  $select = array(
             'Product' => array("ClassName", "$baseClasses[Product].ID","_utf8'' AS ParentID","Content","TechnicalInformation", "$relevance[Product] AS Relevance", "NULL AS CanViewType"),

          foreach($queries as $query) {
		$querySQLs[] = $query->sql();
		//$totalCount += $query->unlimitedRowCount();                 (comented)


and i don't know why but i get error

[User Error] Couldn't run query: SELECT ClassName, `Product_live`.ID, _utf8'' AS ParentID, Content,TechnicalInformation, MATCH (Content,TechnicalInformation) AGAINST ('something' IN BOOLEAN MODE) AS Relevance, NULL AS CanViewType FROM `Product_live` WHERE (MATCH (Content,TechnicalInformation) AGAINST ('something*') AND ClassName = 'Product') AND (`SiteTree_Live`.ClassName IN ('Product')) ORDER BY Relevance DESC LIMIT 0, 10 Unknown column 'SiteTree_Live.ClassName' in 'where clause'

what is this 'AND (`SiteTree_Live`.ClassName IN ('Product'))' and how to fix it ?


Community Member, 14 Posts

4 March 2011 at 11:31pm

hello do you solve the problem and if the answer is yes, please write how do you modify search engine!

with regards