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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

All other Modules /

Discuss all other Modules here.

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

Solr search and indexing files

Go to End

26 Posts   6693 Views


Community Member, 52 Posts

22 March 2012 at 6:45pm

Hi thanks for the reply,

No unfortunately I can't see any errors - just running dev/tasks/SolrReindexTask works fine but only indexes Page and sub classes but not the dataobject.

I've got the searchable fields setup and working well under model admin.
Are there specific fields that need to be on the dataobject?

would you mind posting a sample of your setup?




Administrator, 89 Posts

22 March 2012 at 6:53pm

It's a really basic object with the following fields;

public static $db = array(
'Title' => 'Varchar(255)',
'Description' => 'Text',
'Estimate' => 'Double',
'ElapsedTime' => 'Double',
'CompleteBy' => 'Date',
'Type' => "Enum('Task,Feature,Bug,Request,Ticket')",
'Finished' => 'Boolean',
'FinishedDate' => 'Date',

By default it will automatically map the type of field to an appropriate solr data type - by default the search will search on Title and Description

Do you have the queuedjob module installed at all? If so, it'll actually use a queuedjob for indexing the item - which may not be executing immediately, so check the 'jobs' tab in the cms admin.

If you're comfortable digging in code, the actual indexing occurs in SolrSearchService around line 236 - you can try putting some debug statements in there.


Community Member, 52 Posts

22 March 2012 at 7:15pm

hmmm, no queued job module so i must be missing something simple...

I'll have another look tomorrow when I get back to it.



Community Member, 52 Posts

23 March 2012 at 9:08am


So I've installed the module, and the multifield module, launched jetty/solr from the module directory and added the DataObject::add_extension('Entry', 'SolrIndexable');

have this data object:

class Entry extends DataObject {

	public static $db = array(
		'FirstName' => 'Text',
		'LastName' => 'Text',
		'Caption'	=> 'Text',
		'Location'	=> 'Text'

	public static $has_one = array(
		'Photo' => 'Image',
		'CategoryPage' => 'CategoryPage',
		'ThumbPage'	=> 'ThumbPage'
	  static $searchable_fields = array( 
      'FirstName' => array( 
         'title' => 'FirstName', 
         'filter' => 'PartialMatchfilter'), 
      'LastName' => array( 
         'title' => 'LastName', 
         'filter' => 'PartialMatchfilter'), 
      'Caption' => array( 
         'title' => 'Phototitle', 
         'filter' => 'PartialMatchfilter')
	static $summary_fields = array(
	function ImageTitle() { 
		$pt = $this->Photo()->Name; 
		return $pt;
/*  public function getCustomSearchContext() {
        $fields = $this->scaffoldSearchFields(array(
            'restrictFields' => array('FirstName', 'LastName', 'Caption', 'Category')
        $filters = array(
            'FirstName' => new PartialMatchFilter('FirstName'),
            'LastName' => new PartialMatchFilter('LastName'),
			'Caption' => new PartialMatchFilter('Caption')
        return new SearchContext(
    } */
	public function getCMSFields_forPopup() {
		return new FieldSet(
			new TextField('FirstName'),
			new TextField('LastName'),
			new TextField('Caption'),
			new TextField('Location'),
			/* new DropdownField('CategoryPageID', 'Choose a category', DataObject::get('CategoryPage')->map("ID", "Title", "Please Select")), */
			new ImageField('Photo')
	public function SplitList($val=3) { 
		return ($this->iteratorPos + 1) % $val == 0; 
	function goBack() {
		$src = $this->ThumbPageID;
		$button = SiteTree::get_by_id('ThumbPage', $src);
		return $button;

but still only pages are indexed.

I've added a debug::show at line 143 of SolrSearchService in the index function

	public function index($dataObject, $stage=null) {
		$document = new Apache_Solr_Document();
		$fieldsToIndex = array();

and this returns all my Page types but no data object.

Would there be a better place to put this?


Community Member, 52 Posts

23 March 2012 at 12:42pm

AhHA!! victory is mine,

I tried doing a mass re-import of my dataobjects from csv seeing that there was an index on write function and it worked!

Not sure why it wouldn't index the existing - is this by design?




Community Member, 52 Posts

23 March 2012 at 3:26pm


maybe not quite, whilst it indexed all the objects on write it will only search for them if i use FirstName_t: in the query - adding
SolrSearchService::add_default_query_field('FirstName_t'); doesn't appear to work - it seems like nothing in me _config.php is being honoured... could it be overridden somehow?



Administrator, 89 Posts

23 March 2012 at 4:06pm

It will only index content on save / publish; if you've got existing content not already indexed you'll need to run the dev/tasks/SolrReindexTask . You can pass the parameter 'type' to this to have your item indexed;

The add_default_query_field is only applied if it doesn't use a QueryBuilder object to construct the query - this is probably a bit of an oversight since the idea of QueryBuilders were introduced

As far as actually configuring the search page, I've just pushed a commit that'll make things a bit more manageable via the CMS directly, instead of having to put stuff in _config.php. If you go to the CMS's Solr tab, you can create a SolrTypeConfiguration object. Select your custom data object, and select each of the fields you want to search on (you'll need to make sure to select "Default type" from the second dropdown box for each field)

This will a) automatically add this type to the list of searchable items on the Search page, and b) once you've selected your type and saved the page, the Search on Fields list will contain the field names that you configured above.

That commit's just gone up, so you'll need to grab those changes first!


Community Member, 52 Posts

23 March 2012 at 5:20pm

wow, fantastic! Thanks Marcus you legend.

I'll give it a crack