public function apachesolr_views_query::build in Apache Solr Views 7
Same name and namespace in other branches
- 6 apachesolr_views_query.inc \apachesolr_views_query::build()
Builds what is necessary prior to executing the query.
Overrides views_plugin_query::build
File
- ./
apachesolr_views_query.inc, line 40 - Views query plugin for Apache Solr Views. Gets its data not from the database, but from a Solr server.
Class
- apachesolr_views_query
- @file Views query plugin for Apache Solr Views. Gets its data not from the database, but from a Solr server.
Code
public function build(&$view) {
$view
->init_pager();
// Let the pager modify the query to add limits.
$this->pager
->query();
// Add fields to the query so they will be shown in solr document.
$this->params['fl'] = array_keys($view->field);
$params = array();
if (isset($this->params['q'])) {
$params['q'] = $this->params['q'];
}
$params['rows'] = $this->pager->options['items_per_page'];
$params['start'] = $this->pager->current_page * $this->pager->options['items_per_page'];
// If we display all items without pager.
if ($params['rows'] == 0) {
$params['rows'] = 100000;
}
// Add fields.
$params['fl'] = array(
'id',
'entity_id',
);
if (isset($this->params['fl'])) {
$params['fl'] = array_merge($params['fl'], $this->params['fl']);
}
$params['fl'] = implode(',', $params['fl']);
if (isset($this->params['hl'])) {
$params['hl'] = $this->params['hl'];
}
if (isset($this->params['hl'])) {
$params['f.content.hl.alternateField'] = $this->params['f.content.hl.alternateField'];
}
if (isset($this->params['hl.snippets'])) {
$params['hl.snippets'] = $this->params['hl.snippets'];
}
$where = $this->where;
// Remove any empty conditions (exposed filters), they will cause an error.
foreach ($where as &$where_condition) {
foreach ($where_condition['conditions'] as $index => $condition) {
if ($condition['value'] == '') {
unset($where_condition['conditions'][$index]);
}
}
}
// Add conditions to filter parameter.
$conditions = array(
'conditions' => $where,
'type' => $this->group_operator,
);
$conditions_string = $this
->build_where_string($conditions);
if (!empty($conditions_string)) {
$params['fq'] = $conditions_string;
}
// Set query type if it is present.
if (isset($this->params['defType'])) {
$params['defType'] = $this->params['defType'];
}
$this->query_params = $params;
// Export parameters for preview.
$view->build_info['query'] = var_export($params, TRUE);
}