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

16 December 2014 at 11:31pm

Hi All,

Been a while since I posted anything here, but I am getting some weird results from the FullText filter. When I run:

$results = SiteTree::get()->filter('"Title,Content,URLSegment":FullText', "Search term");

I get the results I expect, but when I run:

$results = Product::get()->filter('"Title,Content,URLSegment":FullText', "Search term");

FulText filters the Title and URLSegment, but seems to ignore the content.

I am using this code for a new module I am writing that extends (hopefully) the default Silverstripe FullTextSearch, which can be found here: https://github.com/i-lateral/silverstripe-searchable

The product is setup the sameway as the SiteTree, using the extension here: https://github.com/i-lateral/silverstripe-searchable/blob/master/code/extensions/SearchableDataObject.php

Anyone got any idea why this isn't working? It has got me stumped?

Cheers,

Mo

Avatar
camfindlay

Forum Moderator, 267 Posts

22 December 2014 at 11:01am

Have you checked that the indexes have been set up on the Product class? http://api.silverstripe.org/master/class-FulltextFilter.html

That FullText SearchFilter looks interesting I didn't even know that one existed (I learn the hidden gems of Framework all the time), if you get things working would you like to add this to the documentation?

Avatar
Mo

Community Member, 541 Posts

6 January 2015 at 4:50am

Edited: 06/01/2015 4:50am

Hi Camfindlay,

The indexes are appearing as expected in the DB, when I look at the indexes I see:

Keyname: SearchFields
Type: FULLTEXT
Column: Title, Content, URLSegment

The only thing I can think that might cause problems is that Product extends CatalogueProduct (in the same way Page extends SiteTree) and all these fields exist on CatalogueProduct.

I have picked appart SiteTree though and cannot see what might make it behave differently.

I am always finding new stuff too, I thought this looked like a good filter to build the module on top of, but it just doesn't seem to behave how I had expected it to. If I can find an answer then I am more than happy to write some docs :-).

Mo

Avatar
martimiz

Forum Moderator, 1391 Posts

7 January 2015 at 12:17am

Might be interesting to check the full mysql query that is generated in both cases?

Avatar
Mo

Community Member, 541 Posts

10 January 2015 at 4:07am

I did do a Debug::show to get the SQL and I didn't see anything odd. Is that the best way to extract the SQL though (using the SQL method) or is their a URL variable I can use?

Avatar
martimiz

Forum Moderator, 1391 Posts

10 January 2015 at 4:47am

Well, there is the ?showqueries=1 but that might not easily work on posting a searchform...

I'd probably just try intercepting the query in FulltextFilter::apptlyOne() and do an echo / exit()...

Avatar
Mo

Community Member, 541 Posts

10 January 2015 at 4:56am

Sounds like a plan! I will try that when I have finished this project I am working on and can go back to working on my search module :-)

Avatar
Mo

Community Member, 541 Posts

3 March 2015 at 7:52am

Hi All,

I finally managed to get round to doing this.

First off I changed the code so that I use:

$results = $classname::get()->filter(array(
    "Title:FullText" => "tgi*",
    "Content:FullText" => "tgi*",
    "URLSegment:FullText" => "tgi*"
));

This throws a MASSIVE fit when I try and execure the query. The SQL generated is:

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") AGAINST ('tgi*')) AND (MATCH (""."Content") AGAINST ('tgi*')) AND (MATCH (""."URLSegment") AGAINST ('tgi*')) ORDER BY "CatalogueProduct"."Title" ASC

I have injected FulltextFilter::applyOne() and for some reson The database name does not seem to be available to the Match statement (using SearchFilter::getDbName()). Anyone got any ideas what might be going on? Is this a bug in Silverstripe?

Any help appreciated? The codebase I am using is at https://github.com/i-lateral/silverstripe-searchable.

Cheers,

Mo

Go to Top