Ejemplo n.º 1
0
 /**
  * Return the fields that can be selected for sorting operations.
  *
  * @param String $listType
  * @return array
  */
 public function getSelectableFields($listType = null, $excludeGeo = true)
 {
     if (!$listType) {
         $listType = $this->owner->searchableTypes('Page');
     }
     $availableFields = $this->solrSearchService->getAllSearchableFieldsFor($listType);
     $objFields = array_combine(array_keys($availableFields), array_keys($availableFields));
     $objFields['LastEdited'] = 'LastEdited';
     $objFields['Created'] = 'Created';
     $objFields['ID'] = 'ID';
     $objFields['score'] = 'Score';
     if ($excludeGeo) {
         // need to filter out any fields that are of geopoint type, as we can't use those for search
         if (!is_array($listType)) {
             $listType = array($listType);
         }
         foreach ($listType as $classType) {
             $db = Config::inst()->get($classType, 'db');
             if ($db && count($db)) {
                 foreach ($db as $name => $type) {
                     $type = current(explode("(", $type));
                     if (is_subclass_of($type, 'SolrGeoPoint') || $type == 'SolrGeoPoint') {
                         unset($objFields[$name]);
                     }
                 }
             }
         }
     }
     ksort($objFields);
     return $objFields;
 }
Ejemplo n.º 2
0
 /**
  * Return the fields that can be selected for sorting operations.
  *
  * @param String $listType
  * @return array
  */
 public function getSelectableFields($listType = null, $excludeGeo = true)
 {
     if (!$listType) {
         $listType = $this->owner->searchableTypes('Page');
     }
     $availableFields = $this->solrSearchService->getAllSearchableFieldsFor($listType);
     $objFields = array_combine(array_keys($availableFields), array_keys($availableFields));
     $objFields['LastEdited'] = 'LastEdited';
     $objFields['Created'] = 'Created';
     $objFields['ID'] = 'ID';
     $objFields['score'] = 'Score';
     if ($excludeGeo) {
         // need to filter out any fields that are of geopoint type, as we can't use those for search
         if (!is_array($listType)) {
             $listType = array($listType);
         }
         foreach ($listType as $classType) {
             $db = Config::inst()->get($classType, 'db');
             if ($db && count($db)) {
                 foreach ($db as $name => $type) {
                     $type = current(explode("(", $type));
                     if (is_subclass_of($type, 'SolrGeoPoint') || $type == 'SolrGeoPoint') {
                         unset($objFields[$name]);
                     }
                 }
             }
         }
     }
     // Remove any custom field types and display the sortable options nicely to the user.
     $objFieldsNice = array();
     foreach ($objFields as $key => $value) {
         if ($customType = strpos($value, ':')) {
             $value = substr($value, 0, $customType);
         }
         // Add spaces between words, other characters and numbers.
         $objFieldsNice[$key] = ltrim(preg_replace(array('/([A-Z][a-z]+)/', '/([A-Z]{2,})/', '/([_.0-9]+)/'), ' $0', $value));
     }
     ksort($objFieldsNice);
     return $objFieldsNice;
 }