Permalink
Browse files

Fixed to actually index objects of a specific type, not all

  • Loading branch information...
1 parent 1913402 commit 47853510cd516af775a375d256d55bb30fe70068 Marcus Nyeholt committed Mar 27, 2012
Showing with 14 additions and 8 deletions.
  1. +14 −8 code/tasks/SolrReindexTask.php
@@ -24,7 +24,7 @@ function run($request)
if (isset($_GET['delete_all'])) {
$search->getSolr()->deleteByQuery('*:*');
} else {
- $search->getSolr()->deleteByQuery('ClassNameHierarchy_ms:Page');
+ $search->getSolr()->deleteByQuery('ClassNameHierarchy_ms:' . $type);
}
$search->getSolr()->commit();
@@ -35,19 +35,25 @@ function run($request)
echo "<p>Reindexing job has been queued</p>";
return;
}
+
// get the holders first, see if we have any that AREN'T in the root (ie we've already partitioned everything...)
- $pages = DataObject::get('Page');
+ $pages = DataObject::get($type);
-
/* @var $search SolrSearchService */
$count = 0;
foreach ($pages as $page) {
- $search->index($page, 'Draft');
- if ($page->Status == 'Published') {
- $search->index($page, 'Live');
+ if ($page->hasField('Status')) {
+ $search->index($page, 'Draft');
+ if ($page->Status == 'Published') {
+ $search->index($page, 'Live');
+ }
+ echo "<p>Reindexed (#$page->ID) $page->Title</p>\n";
+ $count ++;
+ } else {
+ $search->index($page);
+ echo "<p>Reindexed $type ID#$page->ID</p>\n";
+ $count ++;
}
- echo "<p>Reindexed (#$page->ID) $page->Title</p>\n";
- $count ++;
}
echo "Reindex complete, $count objects re-indexed<br/>";
}

0 comments on commit 4785351

Please sign in to comment.