Example #1
0
 public function testSetFields()
 {
     $this->query->clearFields();
     $this->query->addFields(array('field1', 'field2'));
     $this->query->setFields(array('field3', 'field4'));
     $this->assertEquals(array('field3', 'field4'), $this->query->getFields());
 }
 /**
  * Sets up the fields to be fetched by the query.
  *
  * @param array $arguments request arguments
  */
 protected function setFields($arguments)
 {
     $fieldsConfig = SettingsUtility::getMergedSettings('dataFields', $this->settings, $this->getAction());
     $fields = [];
     // Use field list from query parameters or from defaults.
     if (array_key_exists('data-fields', $arguments) && $arguments['data-fields']) {
         $fields = explode(',', $arguments['data-fields']);
     } else {
         if ($fieldsConfig['default']) {
             $fields = array_values($fieldsConfig['default']);
         }
     }
     // If allowed fields are configured, keep only those.
     $allowedFields = $fieldsConfig['allow'];
     if ($allowedFields) {
         $fields = array_intersect($fields, $allowedFields);
     }
     // If disallowed fields are configured, remove those.
     $disallowedFields = $fieldsConfig['disallow'];
     if ($disallowedFields) {
         $fields = array_diff($fields, $disallowedFields);
     }
     // Only set fields of the query if there is a result. Otherwise use the default setting.
     if ($fields) {
         $this->query->setFields($fields);
     }
 }
Example #3
0
 /**
  * Prepare query for to run
  * 
  * @param array $fields to be selected
  * 
  * @return self
  */
 public function prepare(array $fields = null)
 {
     if ($fields !== null) {
         $this->query->setFields($fields);
     }
     $this->query->setQuery($this->rawQuery);
     return $this;
 }
 /**
  * Set fields returned by the query.
  * We do not ask for 'content', because it can be huge for attachments, and is anyway replaced by highlighting.
  *
  * @param Query $solarium_query
  * @param array $field_names
  */
 private function add_fields(Query $solarium_query, $field_names = array(WpSolrSchema::_FIELD_NAME_ID, WpSolrSchema::_FIELD_NAME_TITLE, WpSolrSchema::_FIELD_NAME_NUMBER_OF_COMMENTS, WpSolrSchema::_FIELD_NAME_COMMENTS, WpSolrSchema::_FIELD_NAME_DISPLAY_DATE, WpSolrSchema::_FIELD_NAME_CATEGORIES_STR, WpSolrSchema::_FIELD_NAME_AUTHOR))
 {
     $solarium_query->setFields($field_names);
 }
 /**
  * Set fields returned by the query.
  * We do not ask for 'content', because it can be huge for attachments, and is anyway replaced by highlighting.
  *
  * @param Query $solarium_query
  * @param array $field_names
  */
 private function add_fields(Query $solarium_query)
 {
     // We add '*' to dynamic fields, else they are not returned by Solr (Solr bug ?)
     $solarium_query->setFields(array(WpSolrSchema::_FIELD_NAME_ID, WpSolrSchema::_FIELD_NAME_PID, WpSolrSchema::_FIELD_NAME_TITLE, WpSolrSchema::_FIELD_NAME_NUMBER_OF_COMMENTS, WpSolrSchema::_FIELD_NAME_COMMENTS, WpSolrSchema::_FIELD_NAME_DISPLAY_DATE, WpSolrSchema::_FIELD_NAME_DISPLAY_MODIFIED, '*' . WpSolrSchema::_FIELD_NAME_CATEGORIES_STR, WpSolrSchema::_FIELD_NAME_AUTHOR, '*' . WpSolrSchema::_FIELD_NAME_POST_THUMBNAIL_HREF_STR, '*' . WpSolrSchema::_FIELD_NAME_POST_HREF_STR));
 }