Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions controllers/ResultsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,33 +110,36 @@ protected function _search($offset, $limit, $limitToPublicItems = true)
protected function _getQuery($limitToPublicItems = true)
{

// Get the `q` GET parameter.
$query = $this->_request->q;

// If defined, replace `:`; otherwise, revert to `*:*`.
// Also, clean it up some.
if (!empty($query)) {
$query = str_replace(':', ' ', $query);
$to_remove = array('[', ']');
foreach ($to_remove as $c) {
$query = str_replace($c, '', $query);
}
} else {
$query = '*:*';
// Get the `q` GET parameter in a group.
$q = '(' . trim($this->_request->q) . ')';

// If no `q` GET parameter was specified, match everything.
if ($q === '()') {
$q = '*:*';
}

// Get the `facet` GET parameter
$facet = $this->_request->facet;
// Add the `q` GET parameter to the query as a group.
$query[] = $q;

// Form the composite Solr query.
if (!empty($facet)) $query .= " AND {$facet}";
// Get the `facet` GET parameter.
$facet = trim($this->_request->facet);

// If the `facet` GET parameter was specified, add each individual
// phrase to the query after marking that phrase as required.
if (!empty($facet)) {
foreach (explode(' AND ', $facet) as $field) {
$query[] = '+' . $field;
}
}

// Limit the query to public items if required
if($limitToPublicItems) {
$query .= ' AND public:"true"';
// Add public item limit to the array of query phrases if necessary.
if ($limitToPublicItems) {
$query[] = '+public:"true"';
}

return $query;
// Use the Extended DisMax query parser, and combine all query phrases
// with the AND operator.
return '{!edismax}' . implode(' AND ', $query);

}

Expand Down