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.

Data Model Questions

modify search engine


Reply

2 Posts   1024 Views

Avatar
snaip

21 December 2010 at 4:13am (Last edited: 21 December 2010 4:19am), Community Member, 180 Posts

Hi

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 ?

Avatar
trumi

4 March 2011 at 11:31pm Community Member, 14 Posts

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

with regards
ntrumax