Author: sevein
Date: Sat Apr 28 21:53:28 2012
New Revision: 11545
Log:
Build some facets for the advanced search, they are internally used
Modified:
branches/2.0/apps/qubit/modules/search/actions/advancedAction.class.php
Modified:
branches/2.0/apps/qubit/modules/search/actions/advancedAction.class.php
==============================================================================
--- branches/2.0/apps/qubit/modules/search/actions/advancedAction.class.php
Sat Apr 28 21:52:59 2012 (r11544)
+++ branches/2.0/apps/qubit/modules/search/actions/advancedAction.class.php
Sat Apr 28 21:53:28 2012 (r11545)
@@ -26,14 +26,31 @@
$this->getResponse()->addStylesheet('print-preview', 'last');
}
+ if (!isset($request->limit))
+ {
+ $request->limit = sfConfig::get('app_hits_per_page');
+ }
+
$this->form = new sfForm;
$this->form->getValidatorSchema()->setOption('allow_extra_fields', true);
$this->form->bind($request->getRequestParameters() +
$request->getGetParameters() + $request->getPostParameters());
- if (isset($this->request->searchFields) && $this->form->isValid())
+ $exist = false;
+ foreach ($this->request->searchFields as $item)
+ {
+ if (!empty($item['query']))
+ {
+ $exist = true;
+
+ break;
+ }
+ }
+
+ if ($exist && $this->form->isValid())
{
- $query = new Elastica_Query_Bool();
+ $query = new Elastica_Query;
+ $queryBool = new Elastica_Query_Bool();
foreach ($this->request->searchFields as $key => $item)
{
@@ -105,23 +122,33 @@
switch ($item['operator'])
{
case 'not':
- $query->addMustNot($queryText);
+ $queryBool->addMustNot($queryText);
break;
case 'or':
- $query->addShould($queryText);
+ $queryBool->addShould($queryText);
break;
case 'add':
default:
- $query->addMust($queryText);
+ $queryBool->addMust($queryText);
break;
}
}
+ $query->setQuery($queryBool);
+
+ foreach (array('repository.id', 'digitalObject.mediaTypeId') as $field)
+ {
+ $facet = new Elastica_Facet_Terms($field);
+ $facet->setField($field);
+ $facet->setSize(50);
+ $query->addFacet($facet);
+ }
+
$resultSet =
QubitSearch::getInstance()->index->getType('QubitInformationObject')->search($query);
$this->pager = new QubitSearchPager($resultSet);
@@ -138,7 +165,66 @@
if ($this->pager->hasResults())
{
+ $facets = array();
+
+ // build lookup tables for I18nized values
+ foreach ($resultSet->getFacets() as $name => $facet)
+ {
+ if (isset($facet['terms']))
+ {
+ $ids = array();
+ foreach ($facet['terms'] as $term)
+ {
+ $ids[$term['term']] = $term['count'];
+ }
+ }
+
+ switch ($name)
+ {
+ // NB: this is actually used as a lookup table, not a facet
+ // it could alternately be done by iterating over the result
documents
+ // for a potential performance increase
+ case 'repository.id':
+ $criteria = new Criteria;
+ $criteria->add(QubitRepository::ID, array_keys($ids),
Criteria::IN);
+
+ $repos = QubitRepository::get($criteria);
+
+ foreach ($repos as $repo)
+ {
+ $reponames[$repo->id] =
$repo->getAuthorizedFormOfName(array('cultureFallback' => true, 'culture' =>
$this->context->user->getCulture()));
+ }
+
+ foreach ($facet['terms'] as $term)
+ {
+ $facets[strtr($name, '.', '_')]['terms'][$term['term']] =
array('count' => $term['count'],
+ 'term' =>
$reponames[$term['term']]);
+ }
+
+ break;
+
+ case 'digitalObject.mediaTypeId':
+ $criteria = new Criteria;
+ $criteria->add(QubitTerm::ID, array_keys($ids), Criteria::IN);
+
+ $mediaTypes = QubitTerm::get($criteria);
+
+ foreach ($mediaTypes as $mediaType)
+ {
+ $mediaTypeNames[$mediaType->id] =
$mediaType->getName(array('cultureFallback' => true, 'culture' =>
$this->context->user->getCulture()));
+ }
+
+ foreach ($facet['terms'] as $term)
+ {
+ $facets[strtr($name, '.', '_')]['terms'][$term['term']] =
array('count' => $term['count'],
+ 'term' =>
$mediaTypeNames[$term['term']]);
+ }
+
+ break;
+ }
+ }
+ $this->pager->facets = $facets;
}
}
}
--
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.