Created
June 17, 2016 14:02
-
-
Save wizhippo/729c4a283796ae2a19dd04314de1ae63 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'TocomAssociateSiteBundle::pagelayout.html.twig' %} | |
{% block content %} | |
<div class="content-search"> | |
<div class="box box-primary"> | |
<div class="box-header with-border"> | |
<h3 class="box-title attribute-header">{{ 'Search'|trans }}</h3> | |
</div> | |
<div class="box-body"> | |
{{ form_start( form, {'class': 'form-search'} ) }} | |
{{ form_widget( form.searchText, { 'attr': {'class': 'input-xxlarge search-query','autofocus':'autofocus'}} ) }} | |
{{ form_widget( form.save, { 'label': "Search"|trans, 'attr': { 'class': 'btn' } } ) }} | |
{{ form_errors(form.searchText) }} | |
{{ form_end( form ) }} | |
{% if searchCount > 0 %} | |
<div class="feedback"> | |
<h2>{% trans %}Search for "%searchText%" returned %searchCount% matches{% endtrans %}</h2> | |
</div> | |
<div class="search-facets"> | |
{% for facet in searchResult.facets %} | |
<div>{{ dump(facet) }}</div> | |
{% endfor %} | |
</div> | |
<div class="search-results"> | |
{% for searchHit in searchResult.searchHits %} | |
{{ render( controller( 'ez_content:viewLocation', { | |
'locationId': searchHit.valueObject.versionInfo.contentinfo.mainLocationId, | |
'viewType': 'search' | |
} ) ) }} | |
{% endfor %} | |
</div> | |
{% else %} | |
<div class="warning"> | |
<h2>{% trans %}No results were found when searching for "%searchText%".{% endtrans %}</h2> | |
</div> | |
<p>{{ 'Search tips'|trans }}</p> | |
<ul> | |
<li>{{ 'Check spelling of keywords.'|trans }}</li> | |
<li>{{ 'Try changing some keywords (eg, "car" instead of "cars").'|trans }}</li> | |
<li>{{ 'Try searching with less specific keywords.'|trans }}</li> | |
<li>{{ 'Reduce number of keywords to get more results.'|trans }}</li> | |
</ul> | |
{% endif %} | |
</div> | |
</div> | |
</div> | |
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ExampleBundle\Controller; | |
use eZ\Bundle\EzPublishLegacyBundle\Controller; | |
use eZ\Publish\API\Repository\Values\Content\Query; | |
use eZ\Publish\API\Repository\Values\Content\Query\Criterion; | |
use eZ\Publish\API\Repository\Values\Content\Query\SortClause; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\Response; | |
use ExampleBundle\Entity\SimpleSearch; | |
use ExampleBundle\Form\Type\SimpleSearchType; | |
/** | |
* @Route("/search") | |
*/ | |
class SearchController extends Controller | |
{ | |
/** | |
* @Route("/") | |
*/ | |
public function showSearchResultsAction(Request $request) | |
{ | |
$response = new Response(); | |
$searchText = ''; | |
$searchResult = null; | |
$simpleSearch = new SimpleSearch(); | |
$form = $this->createForm(new SimpleSearchType(), $simpleSearch); | |
$form->handleRequest($request); | |
if ($form->isValid()) { | |
if (!empty($simpleSearch->searchText)) { | |
$searchText = $simpleSearch->searchText; | |
$query = new Query(); | |
$query->query = new Criterion\FullText($searchText); | |
$query->filter = new Criterion\LogicalAnd([ | |
new Criterion\Visibility(Criterion\Visibility::VISIBLE), | |
new Criterion\LanguageCode($this->getConfigResolver()->getParameter('languages')), | |
]); | |
$query->facetBuilders = [ | |
new Query\FacetBuilder\UserFacetBuilder(), | |
new Query\FacetBuilder\ContentTypeFacetBuilder() | |
]; | |
$query->limit = 10; | |
$query->offset = ($request->query->get('page', 1) - 1) * 10; | |
$searchService = $this->get('ezpublish.api.repository')->getSearchService(); | |
$searchResult = $searchService->findContent($query); | |
} | |
} | |
return $this->render( | |
'ExampleBundle:search:search.html.twig', | |
array( | |
'searchText' => $searchText, | |
'searchCount' => isset($searchResult->totalCount) ? $searchResult->totalCount : 0, | |
'searchResult' => $searchResult, | |
'form' => $form->createView(), | |
), | |
$response | |
); | |
} | |
public function searchBoxAction() | |
{ | |
$response = new Response(); | |
$simpleSearch = new SimpleSearch(); | |
$form = $this->createForm(new SimpleSearchType(), $simpleSearch); | |
return $this->render( | |
'ExampleBundle:search:search_box.html.twig', | |
array( | |
'form' => $form->createView(), | |
), | |
$response | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment