Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » modify search engine

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

Page: 1
Go to End
Author Topic: 1002 Views
  • snaip
    Community Member
    180 Posts

    modify search engine Link to this post


    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 ?

  • trumi
    Community Member
    14 Posts

    Re: modify search engine Link to this post

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

    with regards

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.