Author: sevein Date: Thu Apr 26 18:22:25 2012 New Revision: 11532 Log: Issue 2288. More progress in the advanced search.
Modified: branches/2.0/apps/qubit/modules/search/actions/advancedAction.class.php branches/2.0/apps/qubit/modules/search/templates/_advancedSearch.php branches/2.0/apps/qubit/modules/search/templates/_searchResults.php branches/2.0/apps/qubit/modules/search/templates/advancedSuccess.php branches/2.0/js/dominion.js Modified: branches/2.0/apps/qubit/modules/search/actions/advancedAction.class.php ============================================================================== --- branches/2.0/apps/qubit/modules/search/actions/advancedAction.class.php Thu Apr 26 16:51:54 2012 (r11531) +++ branches/2.0/apps/qubit/modules/search/actions/advancedAction.class.php Thu Apr 26 18:22:25 2012 (r11532) @@ -17,18 +17,8 @@ * along with Qubit Toolkit. If not, see <http://www.gnu.org/licenses/>. */ -class SearchAdvancedAction extends SearchIndexAction +class SearchAdvancedAction extends sfAction { - public static - $NAMES = array( - 'searchFields', - 'repository', - 'materialType', - 'mediaType', - 'hasDigitalObject', - 'levelOfDescription', - ); - public function execute($request) { if ('print' == $request->getGetParameter('media')) @@ -39,237 +29,117 @@ $this->form = new sfForm; $this->form->getValidatorSchema()->setOption('allow_extra_fields', true); - foreach ($this::$NAMES as $name) - { - $this->addField($name); - } - $this->form->bind($request->getRequestParameters() + $request->getGetParameters() + $request->getPostParameters()); - if ($this->form->isValid()) + if (isset($this->request->searchFields) && $this->form->isValid()) { - if (isset($request->searchFields)) + $query = new Elastica_Query_Bool(); + + foreach ($this->request->searchFields as $key => $item) { - $this->queryTerms = array(); + if (empty($item['query'])) + { + continue; + } - // we are handling a search request - parent::execute($request); - } - } + $queryText = new Elastica_Query_Text(); - } + switch ($item['field']) + { + case 'identifier': + $queryText->setFieldQuery('identifier', $item['query']); - protected function addField($name) - { - switch ($name) - { - case 'searchFields': + break; - break; + case 'title': + $queryText->setFieldQuery('i18n.title', $item['query']); - case 'repository': - // Get list of repositories - $criteria = new Criteria; + break; - // Do source culture fallback - $criteria = QubitCultureFallback::addFallbackCriteria($criteria, 'QubitActor'); + case 'scopeAndContent': + $queryText->setFieldQuery('i18n.scopeAndContet', $item['query']); - $criteria->addAscendingOrderByColumn('authorized_form_of_name'); + break; - $choices = array(); - $choices[null] = null; - foreach (QubitRepository::get($criteria) as $repository) - { - $choices[$repository->id] = $repository; - } + case 'archivalHistory': + $queryText->setFieldQuery('i18n.archivalHistory', $item['query']); - $this->form->setValidator($name, new sfValidatorChoice(array('choices' => array_keys($choices)))); - $this->form->setWidget($name, new sfWidgetFormSelect(array('choices' => $choices))); + break; - break; + case 'extentAndMedium': + $queryText->setFieldQuery('i18n.extentAndMedium', $item['query']); - case 'materialType': - $criteria = new Criteria; - $criteria->add(QubitTerm::TAXONOMY_ID, QubitTaxonomy::MATERIAL_TYPE_ID); - - // Do source culture fallback - $criteria = QubitCultureFallback::addFallbackCriteria($criteria, 'QubitTerm'); - $criteria->addAscendingOrderByColumn('name'); - - $choices = array(); - $choices[null] = null; - foreach (QubitTerm::get($criteria) as $item) - { - $choices[$item->id] = $item; - } + break; - $this->form->setValidator($name, new sfValidatorChoice(array('choices' => array_keys($choices)))); - $this->form->setWidget($name, new sfWidgetFormSelect(array('choices' => $choices))); + case 'creatorHistory': + $queryText->setFieldQuery('', $item['query']); - break; + break; - case 'mediaType': - // Get list of media types - $criteria = new Criteria; - $criteria->add(QubitTerm::TAXONOMY_ID, QubitTaxonomy::MEDIA_TYPE_ID); - - // Do source culture fallback - $criteria = QubitCultureFallback::addFallbackCriteria($criteria, 'QubitTerm'); - $criteria->addAscendingOrderByColumn('name'); - - $choices = array(); - $choices[null] = null; - foreach (QubitTerm::get($criteria) as $item) - { - $choices[$item->id] = $item; - } + case 'subject': + $queryText->setFieldQuery('', $item['query']); + + break; - $this->form->setValidator($name, new sfValidatorChoice(array('choices' => array_keys($choices)))); - $this->form->setWidget($name, new sfWidgetFormSelect(array('choices' => $choices))); + case 'name': + $queryText->setFieldQuery('', $item['query']); - break; + break; - case 'hasDigitalObject': - $choices = array( - '' => '', - 'true' => $this->context->i18n->__('Yes'), - 'false' => $this->context->i18n->__('No') - ); + case 'place': + $queryText->setFieldQuery('', $item['query']); - $this->form->setValidator($name, new sfValidatorChoice(array('choices' => array_keys($choices)))); - $this->form->setWidget($name, new sfWidgetFormSelect(array('choices' => $choices))); + break; - break; + default: + $queryText->setFieldQuery('_all', $item['query']); - case 'levelOfDescription': - $this->form->setValidator('levelOfDescription', new sfValidatorString); + break; + } - $choices = array(); - $choices[null] = null; - foreach (QubitTaxonomy::getTaxonomyTerms(QubitTaxonomy::LEVEL_OF_DESCRIPTION_ID) as $item) + if (0 == $key) { - $choices[$item->id] = $item; + $item['operator'] == 'add'; } - $this->form->setValidator('levelOfDescription', new sfValidatorString); - $this->form->setWidget('levelOfDescription', new sfWidgetFormSelect(array('choices' => $choices))); + switch ($item['operator']) + { + case 'not': + $query->addMustNot($queryText); - break; - } - } + break; - public function parseQuery() - { - QubitSearch::getInstance(); - $queryBuilt = new Zend_Search_Lucene_Search_Query_Boolean(); + case 'or': + $query->addShould($queryText); - foreach ($this->request->searchFields as $searchField) - { - // if no terms for this field, skip it - if (empty($searchField['query'])) - { - continue; - } + break; - // enclose phrase searches in quotes (strip existing ones) - if ('phrase' == $searchField['match']) - { - $term = '"'.str_replace(array('"', "'"), '', strtolower($searchField['query'])).'"'; - } - else - { - $term = strtolower($searchField['query']); + case 'add': + default: + $query->addMust($queryText); + + break; + } } - $matchString = $term; + $resultSet = QubitSearch::getInstance()->index->getType('QubitInformationObject')->search($query); - // limit to specified field - if (!empty($searchField['field'])) - { - $term = $searchField['field'] . ':' . $term; - } + $this->pager = new QubitSearchPager($resultSet); + $this->pager->setPage($request->page ? $request->page : 1); - if (!empty($searchField['field'])) + if ('print' != $request->getGetParameter('media')) { - $field = ucfirst($searchField['field']); + $this->pager->setMaxPerPage($request->limit); } else { - $field = ('phrase' == $searchField['match']) ? $this->context->i18n->__('Phrase') : $this->context->i18n->__('Keyword(s)'); + $this->pager->setMaxPerPage(500); } - $this->queryTerms[] = array('term' => $field.': '.$matchString, 'operator' => $searchField['operator']); - - // select which boolean operator to use - if (!isset($searchField['operator'])) $searchField['operator'] = null; - switch ($searchField['operator']) + if ($this->pager->hasResults()) { - case 'not': - $token = false; - break; - - case 'or': - $token = null; - break; - - case 'and': - default: - $token = true; - break; - } - - $queryBuilt->addSubquery(QubitSearch::getInstance()->parse($term), $token); - } - - $query = new Zend_Search_Lucene_Search_Query_Boolean(); - $query->addSubquery($queryBuilt, true); - - return $query; - } - - public function filterQuery($query) - { - // limit to a repository if selected - if (!empty($this->request->repository)) - { - $query->addSubquery(QubitSearch::getInstance()->addTerm($this->request->repository, 'repositoryId'), true); - $this->queryTerms[] = array('term' => $this->context->i18n->__('Repository').': '.QubitRepository::getById($this->request->repository)->__toString(), 'operator' => 'and'); - } - // digital object filters - if ('true' == $this->request->hasDigitalObject) - { - $query->addSubquery(QubitSearch::getInstance()->addTerm('true', 'hasDigitalObject'), true); - $this->queryTerms[] = array('term' => $this->context->i18n->__('Digital object is available'), 'operator' => 'and'); - } - else if ('false' == $this->request->hasDigitalObject) - { - $query->addSubquery(QubitSearch::getInstance()->addTerm('false', 'hasDigitalObject'), true); - $this->queryTerms[] = array('term' => $this->context->i18n->__('No digital object is available'), 'operator' => 'and'); - } - - // limit to a media type if selected - if (!empty($this->request->mediaType)) - { - $query->addSubquery(QubitSearch::getInstance()->addTerm($this->request->mediaType, 'mediaTypeId'), true); - $this->queryTerms[] = array('term' => 'mediaType: '.QubitTerm::getById($this->request->mediaType)->__toString(), 'operator' => 'and'); - } - - // limit to a material type if selected - if (!empty($this->request->materialType)) - { - $query->addSubquery(QubitSearch::getInstance()->addTerm($this->request->materialType, 'materialTypeId'), true); - $this->queryTerms[] = array('term' => 'materialType: '.QubitTerm::getById($this->request->materialType)->__toString(), 'operator' => 'and'); - } - - if (!empty($this->request->levelOfDescription)) - { - $query->addSubquery(QubitSearch::getInstance()->addTerm($this->request->levelOfDescription, 'levelOfDescriptionId'), true); - $this->queryTerms[] = array('term' => $this->context->i18n->__('Level of description').': '.$this->request->levelOfDescription, 'operator' => 'and'); + } } - - $query = parent::filterQuery($query); - - return $query; } } Modified: branches/2.0/apps/qubit/modules/search/templates/_advancedSearch.php ============================================================================== --- branches/2.0/apps/qubit/modules/search/templates/_advancedSearch.php Thu Apr 26 16:51:54 2012 (r11531) +++ branches/2.0/apps/qubit/modules/search/templates/_advancedSearch.php Thu Apr 26 18:22:25 2012 (r11532) @@ -1,107 +1,7 @@ <?php echo $form->renderFormTag(url_for(array('module' => 'search', 'action' => $action)), array('name' => 'form', 'method' => 'get')) ?> -<?php if (isset($form->confirm)): ?> - <?php echo $form->renderHiddenFields() ?> - <div style="display: none;"> - -<?php endif; ?> - -<table class="multiRow" style="white-space: nowrap; min-width: 660px;"> - <tbody> - <?php echo get_partial('search/searchFields') ?> - </tbody> -</table> - -<fieldset class="collapsible <?php echo ($form->getValue('repository') . $form->getValue('media') . $form->getValue('hasDigitalObject') . $form->getValue('levelOfDescription') ? '' : 'collapsed') ?>" id="filterLimit"> - - <legend><?php echo __('Filter/Limit') ?></legend> - - <?php if (sfConfig::get('app_multi_repository')): ?> - - <?php echo $form->repository - ->label(__('Repository')) - ->renderRow() ?> - - <?php endif; ?> - - <?php echo $form->materialType - ->label(__('General material designation')) - ->renderRow() ?> - - <?php echo $form->mediaType - ->label(__('Media')) - ->renderRow() ?> - - <?php echo $form->hasDigitalObject - ->label(__('Digital object available')) - ->renderRow() ?> - - <?php echo $form->levelOfDescription->renderRow() ?> - -</fieldset> - -<?php if (isset($form->pager) && 'globalReplace' == $action): ?> - - <div class="form-item form-item-identifier"> - <table> - <tbody> - <tr> - <td> - <?php echo __('Replace') ?>: - </td><td style="padding: 0px;"> - <?php echo $form->pattern->render() ?> - </td><td> - <?php echo __('With') ?>: - </td><td style="padding: 0px;"> - <?php echo $form->replacement->render() ?> - </td><td style="white-space: nowrap;"><?php echo __('in') ?>: - <?php echo $form->column->render() ?> - </td> - </tr> - <tr> - <td colspan="2"> - <?php echo __('Case-sensitive') ?> - <?php echo $form->caseSensitive->render() ?> - </td> - <td colspan="3"> - <?php echo __('Use regular expression syntax') ?> - <?php echo $form->allowRegex->render() ?> - </td> - </tr> - </tbody> - </table> - </div> - -<?php endif; ?> - -<?php if (isset($form->confirm)): ?> - </div> -<?php endif; ?> - -<div class="actions"> - - <h2 class="element-invisible"><?php echo __('Actions') ?></h2> - <div class="content"> - <ul class="clearfix links"> - - <?php if (isset($form->confirm)): ?> - - <li><a href="#" title="<?php echo __('Cancel') ?>" onclick="document.form.submit();"><?php echo __('Cancel') ?></a></li> - <li><input class="danger form-submit" type="submit" value="<?php echo __('Replace') ?>" onclick="document.form.method = 'post';"/></li> - - <?php else: ?> - <input type="submit" name="Submit" class="form-submit" value="<?php echo __('Search') ?>" /> - - <?php if (isset($form->pager) && 'globalReplace' == $action): ?> - <li><a class="delete" href="#" title="<?php echo __('Replace') ?>" onclick="document.form.method = 'post'; document.form.submit();"><?php echo __('Replace') ?></a></li> - <?php endif; ?> - - <?php endif; ?> - - </ul> - </div> -</div> + <?php echo get_partial('search/searchFields') ?> </form> Modified: branches/2.0/apps/qubit/modules/search/templates/_searchResults.php ============================================================================== --- branches/2.0/apps/qubit/modules/search/templates/_searchResults.php Thu Apr 26 16:51:54 2012 (r11531) +++ branches/2.0/apps/qubit/modules/search/templates/_searchResults.php Thu Apr 26 18:22:25 2012 (r11532) @@ -3,9 +3,12 @@ <div class="row"> <div class="span12 hidden-phone"> - <h1><?php echo __('%1% Search Results in %2% Institutions', array( - '%1%' => $pager->getNbResults(), - '%2%' => count($pager->facets['repository_id']['terms']))) ?></h1> + <h1> + <?php echo __('%1% search results', array('%1%' => $pager->getNbResults())) ?> + <?php if (sfConfig::get('app_multi_repository')): ?> + <?php echo __('in %1% institutions', array('%1%' => count($pager->facets['repository_id']['terms']))) ?> + <?php endif; ?> + </h1> </div> <div id="phone-filter" class="span12 visible-phone"> Modified: branches/2.0/apps/qubit/modules/search/templates/advancedSuccess.php ============================================================================== --- branches/2.0/apps/qubit/modules/search/templates/advancedSuccess.php Thu Apr 26 16:51:54 2012 (r11531) +++ branches/2.0/apps/qubit/modules/search/templates/advancedSuccess.php Thu Apr 26 18:22:25 2012 (r11532) @@ -1,42 +1,52 @@ <?php use_helper('Text') ?> -<?php if ('print' == $sf_request->getParameter('media')): ?> - <div id="preview-message"> - <?php echo __('Print preview') ?> - <?php echo link_to('Close', array_diff($sf_request->getParameterHolder()->getAll(), array('media' => 'print'))) ?> - </div> -<?php endif; ?> +<div id="advanced-search"> -<h1 class="label"> - <?php echo ('Advanced search') ?> + <?php if ('print' == $sf_request->getParameter('media')): ?> + <div id="preview-message"> + <?php echo __('Print preview') ?> + <?php echo link_to('Close', array_diff($sf_request->getParameterHolder()->getAll(), array('media' => 'print'))) ?> + </div> + <?php endif; ?> + + <h1> + <?php echo ('Advanced search') ?> + <div id="action-icons"> + <?php echo link_to( + image_tag('printer-icon.png', array('alt' => __('Print'))), + array_merge($sf_request->getParameterHolder()->getAll(), array('media' => 'print')), + array('title' => __('Print'))) ?> + </div> + </h1> + + <div class="row"> + <div class="span12"> + + <div id="content"> + <?php if ('print' != $sf_request->getParameter('media')): ?> + <?php echo get_partial('search/advancedSearch', array('form' => $form, 'action' => 'advanced')) ?> + <?php else: ?> + <?php echo get_partial('search/printAdvancedSearchTerms', array('queryTerms' => $queryTerms)) ?> + <?php endif; ?> + </div> - <div id="action-icons"> - <?php echo link_to( - image_tag('printer-icon.png', array('alt' => __('Print'))), - array_merge($sf_request->getParameterHolder()->getAll(), array('media' => 'print')), - array('title' => __('Print'))) ?> + </div> </div> -</h1> + <?php if (isset($error)): ?> -<?php if ('print' != $sf_request->getParameter('media')): ?> - <?php echo get_partial('search/advancedSearch', array('form' => $form, 'action' => 'advanced')) ?> -<?php else: ?> - <?php echo get_partial('printAdvancedSearchTerms', array('queryTerms' => $queryTerms)) ?> -<?php endif; ?> - -<?php if (isset($error)): ?> - - <div class="error"> - <ul> - <li><?php echo $error ?></li> - </ul> - </div> + <div class="error"> + <ul> + <li><?php echo $error ?></li> + </ul> + </div> + + <?php endif; ?> -<?php endif; ?> + <?php if (isset($pager)): ?> -<?php if (isset($pager)): ?> + <?php echo get_partial('search/searchResults', array('pager' => $pager)) ?> - <?php echo get_partial('search/searchResults', array('pager' => $pager, 'timer' => $timer)) ?> + <?php endif; ?> -<?php endif; ?> +</div> Modified: branches/2.0/js/dominion.js ============================================================================== --- branches/2.0/js/dominion.js Thu Apr 26 16:51:54 2012 (r11531) +++ branches/2.0/js/dominion.js Thu Apr 26 18:22:25 2012 (r11532) @@ -231,6 +231,7 @@ { self.hide(); self.$realm.hide(); + self.$element.val(''); }, 150); }, @@ -475,7 +476,7 @@ this .cloneLastCriteria() .insertAfter(this.getLastCriteria()) - .find('input, select').first().focus(); + .find('.criterion input').first().focus(); }, getLastCriteria: function() -- You received this message because you are subscribed to the Google Groups "Qubit Toolkit Commits" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/qubit-commits?hl=en.
