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.

All other Modules /

Discuss all other Modules here.

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

Solr search and indexing files


Reply


26 Posts   3618 Views

Avatar
BlueO

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?

cheers

Bernard

Avatar
Marcus

Administrator, 86 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.

Avatar
BlueO

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.

cheers

Avatar
BlueO

Community Member, 52 Posts

23 March 2012 at 9:08am

Right,

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(
      'FirstName',
      'LastName',
      'Caption',
      'Location',
      'CategoryPage.Title',
      'ThumbPage.Title',
      'ImageTitle'
   );
   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(
$this->class,
$fields,
$filters
);
} */
   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();
Debug::show($dataObject);

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

Would there be a better place to put this?

Avatar
BlueO

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?

cheers

b

Avatar
BlueO

Community Member, 52 Posts

23 March 2012 at 3:26pm

Hmmm,

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?

b

Avatar
Marcus

Administrator, 86 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;

http://mysite.com/dev/tasks/SolrReindexTask?type=Entry

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! https://github.com/nyeholt/silverstripe-solr/commit/1913402ae364ca3c1e38202f12c448f5eaadedf4

Avatar
BlueO

Community Member, 52 Posts

23 March 2012 at 5:20pm

wow, fantastic! Thanks Marcus you legend.

I'll give it a crack