-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from xi-project/2.1
2.1 to master
- Loading branch information
Showing
15 changed files
with
468 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Xi\Bundle\SearchBundle\Event\Subscriber; | ||
|
||
use Knp\Component\Pager\Event\ItemsEvent; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Knp\Component\Pager\Event\Subscriber\Paginate\ElasticaQuerySubscriber as BaseSubscriber; | ||
|
||
/** | ||
* Elastica query pagination. | ||
* Return the Elastica_ResultSet instead of it's results | ||
*/ | ||
class ElasticaQuerySubscriber extends BaseSubscriber | ||
{ | ||
/** | ||
* @param ItemsEvent $event | ||
*/ | ||
public function items(ItemsEvent $event) | ||
{ | ||
if (is_array($event->target) && 2 === count($event->target) && isset($event->target[0], $event->target[1]) && | ||
$event->target[0] instanceof \Elastica_Searchable && $event->target[1] instanceof \Elastica_Query) { | ||
list($searchable, $query) = $event->target; | ||
|
||
$query->setFrom($event->getOffset()); | ||
$query->setLimit($event->getLimit()); | ||
$results = $searchable->search($query); | ||
|
||
$event->count = $results->getTotalHits(); | ||
if ($results->hasFacets()) { | ||
$event->setCustomPaginationParameter('facets', $results->getFacets()); | ||
} | ||
$event->items = $results; | ||
$event->stopPropagation(); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
$ = jQuery | ||
$.fn.xiSearchPaginate = (options) -> | ||
defaultOptions = | ||
page: '#xi_searchbundle_searchtype_page' | ||
submit: '#xi_searchbundle_searchtype_submit' | ||
term: '#xi_searchbundle_searchtype_term' | ||
indices: [] | ||
|
||
options = $.extend true, {}, defaultOptions, options | ||
|
||
# change page | ||
@.on "click", ".pagination a", -> | ||
pageValue = $(this).attr("data-page") | ||
$(options.page).val pageValue | ||
$(options.submit).find("button").trigger "click", silent: true | ||
|
||
# reset page | ||
$(options.term).change -> | ||
$(options.page).val 1 | ||
|
||
if options.indices | ||
for index in options.indices | ||
$(index).change -> | ||
$(options.page).val 1 | ||
|
||
$(options.submit).find("button").click (event, data) -> | ||
unless data and data.silent | ||
$(options.page).val 1 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{# default Sliding pagination control implementation #} | ||
|
||
{% if pageCount > 1 %} | ||
<div class="pages"> | ||
{% if first is defined and current != first %} | ||
<span class="first"> | ||
<a href="#main-content" data-page="{{first}}"><<</a> | ||
</span> | ||
{% endif %} | ||
|
||
{% if previous is defined %} | ||
<span class="previous"> | ||
<a href="#main-content" data-page="{{previous}}"><</a> | ||
</span> | ||
{% endif %} | ||
|
||
{% for page in pagesInRange %} | ||
{% if page != current %} | ||
<span class="page"> | ||
<a href="#main-content" data-page="{{ page }}">{{ page }}</a> | ||
</span> | ||
{% else %} | ||
<span class="current">{{ page }}</span> | ||
{% endif %} | ||
|
||
{% endfor %} | ||
|
||
{% if next is defined %} | ||
<span class="next"> | ||
<a href="#main-content" data-page="{{next}}">></a> | ||
</span> | ||
{% endif %} | ||
|
||
{% if last is defined and current != last %} | ||
<span class="last"> | ||
<a href="#main-content" data-page="{{last}}">>></a> | ||
</span> | ||
{% endif %} | ||
</div> | ||
{% endif %} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{# sorting of properties based on queried types.. | ||
<span>{{ pagination.sortable('Id', 'x.id')|raw }}</span> | ||
#} | ||
|
||
{% for result in results %} | ||
{{ xi_search_result(result, options) }} | ||
{% endfor %} | ||
<div class="clear"></div> | ||
|
||
<div class="pagination"> | ||
{{ results.render()|raw }} | ||
</div> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<form action="{{ path('XiSearchBundle_search') }}" class="ajax-form article-form" method="post" {{ form_enctype(form) }}> | ||
{{ form_widget(form.term, { 'attr': {'placeholder' : ('search.form.term.placeholder')|trans} }) }} | ||
{{ form_rest(form) }} | ||
<p> | ||
<p id="xi_searchbundle_searchtype_submit"> | ||
<button type="submit">{{'search.form.submit_button'|trans}}</button> | ||
</p> | ||
</form> |
Oops, something went wrong.