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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

FulltextSearch not working


Go to End


2 Posts   2097 Views

Avatar
Andre

Community Member, 146 Posts

19 August 2015 at 12:16am

Hi, I'm trying to follow this tutorial to implement Fulltext Search on a DataObject.

https://docs.silverstripe.org/en/3.1/developer_guides/search/fulltextsearch/

My Object looks the followin:

class Item extends DataObject {
	
	private static $db = array(
		"Title" => "Varchar(255)",
		"Teaser" => "Text",
		"Content" => "Text"
	);

    private static $indexes = array(
        'SearchFields' => array(
            'type' => 'fulltext',
            'name' => 'SearchFields',
            'value' => '"Title", "Teaser", "Content"',
        )
    );
}

I'm trying to return a List of Objects using the folowing Filter/Variants, but neither of them is working.

Item::get()->filter(array("SearchFields:Fulltext" => $query));

Item::get()->filter(array("Title,Teaser,Content:Fulltext" => $query));

Item::get()->filter(array("'Title','Teaser','Content':Fulltext" => $query));

The MySQL Error I get returned is the follwoing:

Couldn't run query: SELECT DISTINCT count(DISTINCT "Item"."ID") AS "0" FROM "Item" WHERE (MATCH (""."SearchFields") AGAINST ('centro')) Unknown column 'SearchFields' in 'where clause'

[User Error] Couldn't run query: SELECT DISTINCT count(DISTINCT "Item"."ID") AS "0" FROM "Item" WHERE (MATCH (""."Title,Teaser,Content") AGAINST ('centro')) Unknown column 'Title,Teaser,Content' in 'where clause'

[User Error] Couldn't run query: SELECT DISTINCT count(DISTINCT "Item"."ID") AS "0" FROM "Item" WHERE (MATCH (""."'Title','Teaser','Content'") AGAINST ('centro')) Unknown column ''Title','Teaser','Content'' in 'where clause'

am I missing anything? I did not converted my TAbles to MyISAM, because I'm using MySQL 5.6 which is also supporting fulltext search on InnoDB, so that shouldn't be the point. But What I really do not understand (tried allready to dive into FulltextFilter) is why the filtered tables are taken as a Table.Column (""."SearchFields") notation and where the hack can I change this.

I'm running Silverstripe 3.1.13 currently.

Avatar
Pyromanik

Community Member, 419 Posts

19 August 2015 at 8:44pm

Your DataObject has no such valid column 'Title,Teaser,Content' (think of it like you going $item->Title,Teaser,Trailer or $item->Searchfields - these aren't fields, on your object, nor in the database).
You're looking for:

Item::get()->filterAny([
	'Title:Fulltext' => $query,
	'Teaser:Fulltext' => $query,
	'Content:Fulltext' => $query
])