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.

Template Questions /

Search result page: use MetaDescription as description (just like Google Search)


Go to End
Reply


10 Posts   3557 Views

Avatar
ck_bullet

Community Member, 16 Posts

1 October 2010 at 5:38am

So I'm using a similar query to what CodeGuerilla posted:

$results = DataObject::get('Product',
"Title LIKE '%".$this->searchEntry."%' ".
"OR Brand LIKE '%".$this->searchEntry."%' ".
"OR PartNumber LIKE '%".$this->searchEntry."%' ".
"OR MetaTitle LIKE '%".$this->searchEntry."%' ".
"OR MetaDescription LIKE '%".$this->searchEntry."%' ".
"OR FIND_IN_SET('".trim($this->searchEntry)."', `MetaKeywords`) > 0", "Title ASC", NULL, "{$SQL_start},".Page::$resultsPerPage);

with an additional AND clause like: AND (ClassName = 'Lorem' OR ClassName = 'Ipsum')

Everything works great, but I would like to enhance the query:

So let's say class 'Lorem' has a child class 'LoremChild'. I would like to modify the query so that it returns 'Lorem' items where any of it's children also have Title LIKE OR Brand LIKE, etc. I don't want the actual child item to be returned in the query, only the parent 'Lorem' item. Any help on this query is greatly appreciated!

Avatar
NickJacobs

Community Member, 144 Posts

22 June 2012 at 11:41am

Edited: 22/06/2012 11:42am

Hi banal, I know this is an old post, but hoping you could help with your CustomSearch function.

It seems to me that you are specifically excluding Files by not including them in the classes array:

protected $classesToSearch = array("SiteTree");

Is that the case? I've been trying to exclude files from the site search, but with no luck...this still returns files. Any ideas?

Go to Top