Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend advanced search with query types like in global search. #732

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions admin/themes/default/items/search-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@
array('id' => 'keyword-search', 'size' => '40')
);
?>
<span id="query-types">
<?php
$validQueryTypes = get_search_query_types();
if (isset($_REQUEST['search_type']) && isset($validQueryTypes[$_REQUEST['search_type']])) {
$defaultQueryType = $_REQUEST['search_type'];
} else {
// use same default query type as for global search
$defaultQueryType = apply_filters('search_form_default_query_type', 'keyword');
}
echo $this->formRadio('search_type', $defaultQueryType, array(), $validQueryTypes, '');
?>
</span>
</div>
</div>
<div id="search-narrow-by-fields" class="field">
Expand Down
18 changes: 14 additions & 4 deletions application/models/Table/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function filterBySearch($select, $params)
//Apply the simple or advanced search
if (isset($params['search']) || isset($params['advanced'])) {
if ($simpleTerms = @$params['search']) {
$this->_simpleSearch($select, $simpleTerms);
$this->_simpleSearch($select, $simpleTerms, @$params['search_type']);
}
if ($advancedTerms = @$params['advanced']) {
$this->_advancedSearch($select, $advancedTerms);
Expand All @@ -41,9 +41,10 @@ public function filterBySearch($select, $params)
* tagged items show up higher on the found results list for a given search.
*
* @param Zend_Db_Select $select
* @param string $simpleTerms
* @param string $terms
* @param string $type
*/
protected function _simpleSearch($select, $terms)
protected function _simpleSearch($select, $terms, $type = 'exact_match')
{
$db = $this->getDb();

Expand Down Expand Up @@ -71,7 +72,16 @@ protected function _simpleSearch($select, $terms)
array()
);

$whereCondition = $db->quoteInto('_simple_etx.text LIKE ?', '%' . $terms . '%')
// Set the where clause according to the search type.
if ($type == 'keyword') {
$where = 'MATCH (_simple_etx.text) AGAINST (?)';
} elseif ($type == 'boolean') {
$where = 'MATCH (_simple_etx.text) AGAINST (? IN BOOLEAN MODE)';
} else {
$where = '_simple_etx.text LIKE ?';
$terms = "%{$terms}%";
}
$whereCondition = $db->quoteInto($where, $terms)
. ' OR '
. $db->quoteInto('_simple_tags.name IN (?)', $tagList);
$select->where($whereCondition);
Expand Down
12 changes: 11 additions & 1 deletion application/views/helpers/ItemSearchFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,21 @@ public function itemSearchFilters(array $params = null)
$displayValue = ($value == 1 ? __('Yes') : $displayValue = __('No'));
break;

case 'search':
case 'tags':
case 'range':
$displayValue = $value;
break;

case 'search':
$displayValue = $value;
// we need to merge search & search_type into single criteria (if we want to remove it later)
if (!empty($requestArray['search_type'])) {
$validQueryTypes = get_search_query_types();
if (isset($validQueryTypes[$requestArray['search_type']])) {
$displayValue .= ' ('. __('Query type:') .' '. $validQueryTypes[$requestArray['search_type']] .')';
}
}
break;
}
if ($displayValue) {
$displayArray[$filter] = $displayValue;
Expand Down