I have been using the SearchContext object to create a Custom Search on a subclass of Member and that has been working really well when I do ExactMatchFilter or PartialMatchFilter on separate fields.
I now wanted to add an additional Search form that consists of only one input field and does a fulltext search on a number of fields.
So, in my Member class I have added
static $indexes = array(fulltext (field1,field2,..) )
and I can see in the database that the index has been added.
If I now create a new SearchContext, couldn't I match the input from the Search field against several fields in the Member class (I have checked they are all of Char, VarChar or Text type) [aah.. wrong question already. It's the other way round, matching the fields against the input! /edit 5 Dec 2010]
I tried an awful lot last night and could not get it to work. But I am not sure now if that is because it is too complex, or because I just got muddled up in my thinking. I also came across this thread started by UncleCheese [url]http://www.silverstripe.org/all-other-modules/show/6641?start=24[/url] and tried to implement the version that Aram posted, but did not get it to work.
What I had previously tried is putting something like this in my extended Member class:
return new SearchContext(
$fields = new FieldSet(array(
$filters = array(
//tried various different things here
'FulltextSearch' => new FulltextFilter('field1')
I think there is something wrong in the way I write the $filters array. Either I get error messages, or I get all Data sets returned. Is it maybe just not possible to do a search on more than one field at a time?
So, I have two questions really:
1. Is the type of Search I am aiming at just very difficult to achieve?
2. Is there something where I go wrong with the syntax of the SearchContext?
I'd really appreciate your help. I should maybe mention I have read about the Sphinx module, and I would like to try it out, but at some later stage. If it is at all possible to get it going without that module for now, that would be great.
[edited 5 Dec 2010]