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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

FullText Filter not working on "Content"


Go to End


11 Posts   2649 Views

Avatar
Mo

Community Member, 541 Posts

3 March 2015 at 11:36pm

So I have now read lots of docs on FullText searching. From what I understand the update I have written is not the way to use the FullText search filter, so I have changed it back.

My sql query now reads (I have made it phpmyadmin friendly as I have been trying to tweak it to see if it will work):

SELECT DISTINCT
`CatalogueProduct`.`ClassName`,
`CatalogueProduct`.`Created`,
`CatalogueProduct`.`LastEdited`,
`CatalogueProduct`.`Title`,
`CatalogueProduct`.`StockID`,
`CatalogueProduct`.`BasePrice`,
`CatalogueProduct`.`URLSegment`,
`CatalogueProduct`.`Content`,
`CatalogueProduct`.`MetaDescription`,
`CatalogueProduct`.`ExtraMeta`,
`CatalogueProduct`.`Disabled`,
`CatalogueProduct`.`StockLevel`,
`CatalogueProduct`.`PackSize`,
`CatalogueProduct`.`Weight`,
`CatalogueProduct`.`TaxRateID`,
`CatalogueProduct`.`ID`,
CASE WHEN `CatalogueProduct`.`ClassName` IS NOT NULL
THEN `CatalogueProduct`.`ClassName` ELSE 'CatalogueProduct' END AS `RecordClassName`
FROM `CatalogueProduct`
WHERE (MATCH (``.`Title`,`Content`,`URLSegment`) AGAINST ('tgi*'))
AND (`CatalogueProduct`.`Disabled` = '0')
ORDER BY `CatalogueProduct`.`Title` ASC

The MATCH function is still missing the DB name, but erven if I change this. the search returns no results. I am finding this very confusing, somtimes I get results, other times I don't (when I should)...

Avatar
Christopher Darling

Community Member, 6 Posts

5 March 2015 at 1:11am

How many matches should that be returning? and how many total rows in the table do you have?

Avatar
martimiz

Forum Moderator, 1391 Posts

5 March 2015 at 5:25am

Edited: 05/03/2015 5:28am

Ok... Assuming you are using the native SilverStripe FulltextFilter I took a look at the code, and it doesn't quite look the same as the other filters (like PartialMatch or ExactMatch):

FullText filter:

	protected function applyOne(DataQuery $query) {
		return $query->where(sprintf(
			"MATCH (%s) AGAINST ('%s')",
			$this->getDbName(),
			Convert::raw2sql($this->getValue())
		));
	}

ExactMatch filter (and others):

	protected function applyOne(DataQuery $query) {
		$this->model = $query->applyRelation($this->relation);
		$modifiers = $this->getModifiers();
		$where = DB::getConn()->comparisonClause(
			$this->getDbName(),
			Convert::raw2sql($this->getValue()),
			true, // exact?
			false, // negate?
			$this->getCaseSensitive()
		);
		return $query->where($where);
	}

So maybe it's just missing the 'applyRelation' bit, which would lead to something like this:

	protected function applyOne(DataQuery $query) {
		$this->model = $query->applyRelation($this->relation);
		$modifiers = $this->getModifiers();
		$where = sprintf(
			"MATCH (%s) AGAINST ('%s')",
			$this->getDbName(),
			Convert::raw2sql($this->getValue())
		);
		return $query->where($where);
	}

And something similar for excludeOne(). But this is really just a shot in the dark :-)

Go to Top