mirror of
https://github.com/ToxicCrack/PrintABrick.git
synced 2025-05-17 04:40:08 -07:00
Fix pagination
This commit is contained in:
parent
8ad9c14765
commit
ed5c70d349
@ -25,8 +25,8 @@
|
||||
<div class="ui header vertical noborder">
|
||||
<div class="ui text menu right floated">
|
||||
<div class="header item">Sort By</div>
|
||||
{{ knp_pagination_sortable(models, 'Number', 'm.id', {'class':'item'}) }}
|
||||
{{ knp_pagination_sortable(models, 'Name', ['m.name'], {'class':'item'}) }}
|
||||
{{ knp_pagination_sortable(models, 'Number', 'm.id') }}
|
||||
{{ knp_pagination_sortable(models, 'Name', 'm.name') }}
|
||||
</div>
|
||||
<div class="found-count ui text menu">
|
||||
<div class="header item">Showing</div>
|
||||
|
12
app/Resources/views/pagination/sortable_link.html.twig
Normal file
12
app/Resources/views/pagination/sortable_link.html.twig
Normal file
@ -0,0 +1,12 @@
|
||||
{% if options['class'] == 'asc' %}
|
||||
{% set icon = '<i class="icon sort content ascending"></i>' %}
|
||||
{% set class = 'item active' %}
|
||||
{% elseif options['class'] == 'desc' %}
|
||||
{% set icon = '<i class="icon sort content descending"></i>' %}
|
||||
{% set class = 'item active' %}
|
||||
{% else %}
|
||||
{% set icon = null %}
|
||||
{% set class = 'item' %}
|
||||
{% endif %}
|
||||
|
||||
<a class="{{ class }}" {% for attr, value in options %} {{ attr }}="{{ value }}"{% endfor %}>{{ icon|raw }} {{ title }}</a>
|
@ -29,10 +29,12 @@
|
||||
<div class="ui header vertical noborder">
|
||||
<div class="ui text menu right floated">
|
||||
<div class="header item">Sort By</div>
|
||||
{{ knp_pagination_sortable(sets, 'Number', 's.id', {'class':'item'}) }}
|
||||
{{ knp_pagination_sortable(sets, 'Year', 's.year', {'class':'item'}) }}
|
||||
{{ knp_pagination_sortable(sets, 'Name', ['s.name'], {'class':'item'}) }}
|
||||
{{ knp_pagination_sortable(sets, 'Parts', ['s.partCount'], {'class':'item'}) }}
|
||||
|
||||
{{ knp_pagination_sortable(sets, 'Number', ['s.id']) }}
|
||||
{{ knp_pagination_sortable(sets, 'Year', ['s.year']) }}
|
||||
{{ knp_pagination_sortable(sets, 'Name', ['s.name']) }}
|
||||
{{ knp_pagination_sortable(sets, 'Parts', ['s.partCount']) }}
|
||||
|
||||
</div>
|
||||
<div class="found-count ui text menu">
|
||||
<div class="header item">Showing</div>
|
||||
|
@ -99,15 +99,15 @@ knp_menu:
|
||||
default_renderer: twig
|
||||
|
||||
knp_paginator:
|
||||
page_range: 10 # default page range used in pagination control
|
||||
page_range: 5 # default page range used in pagination control
|
||||
default_options:
|
||||
page_name: page # page query parameter name
|
||||
sort_field_name: sort # sort field query parameter name
|
||||
sort_direction_name: direction # sort direction query parameter name
|
||||
sort_direction_name: dir # sort direction query parameter name
|
||||
distinct: true # ensure distinct results, useful when ORM queries are using GROUP BY statements
|
||||
template:
|
||||
pagination: :pagination:knp_pagination.html.twig
|
||||
sortable: KnpPaginatorBundle:Pagination:sortable_link.html.twig # sort link template
|
||||
sortable: :pagination:sortable_link.html.twig
|
||||
|
||||
oneup_flysystem:
|
||||
adapters:
|
||||
|
@ -10,27 +10,31 @@ fos_elastica:
|
||||
custom_analyzer:
|
||||
type: custom
|
||||
tokenizer: nGram
|
||||
filter: [lowercase, snowball]
|
||||
filter: [lowercase,stopwords]
|
||||
tokenizer:
|
||||
nGram:
|
||||
type: nGram
|
||||
min_gram: 3
|
||||
max_gram: 10
|
||||
max_gram: 20
|
||||
filter:
|
||||
snowball:
|
||||
type: snowball
|
||||
language: English
|
||||
stopwords:
|
||||
type: stop
|
||||
stopwords: [_english_]
|
||||
ignore_case : true
|
||||
types:
|
||||
set:
|
||||
mappings:
|
||||
id: { analyzer: custom_analyzer, search_analyzer: "standard" }
|
||||
id: ~
|
||||
name: { analyzer: custom_analyzer, search_analyzer: "standard" }
|
||||
year: { type: integer }
|
||||
partCount: { type: integer }
|
||||
theme:
|
||||
type: "object"
|
||||
properties:
|
||||
id: { analyzer: custom_analyzer, search_analyzer: "standard" }
|
||||
id: ~
|
||||
name: { analyzer: custom_analyzer, search_analyzer: "standard" }
|
||||
persistence:
|
||||
driver: orm
|
||||
@ -40,16 +44,16 @@ fos_elastica:
|
||||
repository: AppBundle\Repository\Search\SetRepository
|
||||
model:
|
||||
mappings:
|
||||
id: { analyzer: custom_analyzer, search_analyzer: "standard" }
|
||||
id: ~
|
||||
name: { analyzer: custom_analyzer, search_analyzer: "standard" }
|
||||
aliases:
|
||||
type: "object"
|
||||
properties:
|
||||
id: { analyzer: custom_analyzer, search_analyzer: "standard" }
|
||||
id: ~
|
||||
category:
|
||||
type: "object"
|
||||
properties:
|
||||
id: { analyzer: custom_analyzer, search_analyzer: "standard" }
|
||||
id: ~
|
||||
name: { analyzer: custom_analyzer, search_analyzer: "standard" }
|
||||
keywords:
|
||||
type: "object"
|
||||
|
@ -5,6 +5,7 @@ namespace AppBundle\Controller;
|
||||
use AppBundle\Entity\LDraw\Model;
|
||||
use AppBundle\Form\Search\ModelSearchType;
|
||||
use AppBundle\Model\ModelSearch;
|
||||
use Knp\Component\Pager\Paginator;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
@ -32,15 +33,9 @@ class ModelController extends Controller
|
||||
$form->handleRequest($request);
|
||||
|
||||
$elasticaManager = $this->get('fos_elastica.manager');
|
||||
$results = $elasticaManager->getRepository(Model::class)->search($modelSearch);
|
||||
|
||||
$paginator = $this->get('knp_paginator');
|
||||
$sets = $paginator->paginate(
|
||||
$results,
|
||||
$request->query->getInt('page', 1)/*page number*/,
|
||||
$request->query->getInt('limit', 30)/*limit per page*/
|
||||
);
|
||||
$results = $elasticaManager->getRepository(Model::class)->search($modelSearch,5000);
|
||||
|
||||
/** @var Paginator $paginator */
|
||||
$paginator = $this->get('knp_paginator');
|
||||
$models = $paginator->paginate(
|
||||
$results,
|
||||
|
@ -37,13 +37,13 @@ class ModelRepository extends Repository
|
||||
return new Query($boolQuery);
|
||||
}
|
||||
|
||||
public function search(ModelSearch $modelSearch)
|
||||
public function search(ModelSearch $modelSearch, $limit = 500)
|
||||
{
|
||||
$query = $this->getSearchQuery($modelSearch);
|
||||
return $this->find($query, 500);
|
||||
return $this->find($query, $limit);
|
||||
}
|
||||
|
||||
public function findHighlighted($query, $limit = null) {
|
||||
public function findHighlighted($query, $limit = 500) {
|
||||
$modelSearch = new ModelSearch();
|
||||
$modelSearch->setQuery($query);
|
||||
|
||||
|
@ -27,9 +27,9 @@ class SetRepository extends Repository
|
||||
$query->setQuery($searchQuery);
|
||||
$query->setFuzziness(0.7);
|
||||
$query->setMinimumShouldMatch('80%');
|
||||
|
||||
$query->setOperator('and');
|
||||
|
||||
$boolQuery->addMust($query);
|
||||
|
||||
} else {
|
||||
$query = new \Elastica\Query\MatchAll();
|
||||
$boolQuery->addMust($query);
|
||||
@ -69,7 +69,7 @@ class SetRepository extends Repository
|
||||
return $this->find($query, $limit);
|
||||
}
|
||||
|
||||
public function findHighlighted($query, $limit = null) {
|
||||
public function findHighlighted($query, $limit = 500) {
|
||||
$setSearch = new SetSearch();
|
||||
$setSearch->setQuery($query);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user