Skip to content

Commit

Permalink
added a configurable default limit for searches. added configuration …
Browse files Browse the repository at this point in the history
…instructions to readme
  • Loading branch information
joonsp committed Aug 17, 2012
1 parent 9f500d7 commit 7f859cb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
12 changes: 7 additions & 5 deletions Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ public function searchAction()

return $this->processForm($service->getSearchForm(), function($form) use($self, $service, $config) {
$data = $form->getData();


$limit = isset($config['default_limit']) ? $config['default_limit'] : null;

if($data->getSearchType() == 'search'){
$results = $service->search($data->getIndex(), $data->getTerm());
$results = $service->search($data->getIndex(), $data->getTerm(), $config['default_limit']);
} elseif($data->getSearchType() == 'find') {
$results = $service->find($data->getIndex(), $data->getTerm());
}
$results = $service->find($data->getIndex(), $data->getTerm(), $config['default_limit']);
}

$resultHtml = $self->renderView('XiSearchBundle:Search:search.html.twig', array(
'results' => $results, 'index' => $data->getIndex(), 'options' => json_decode($data->getOptions())
));
Expand Down
6 changes: 4 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ public function getConfigTreeBuilder()
// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.

$rootNode
->children()
->variableNode('result_renderer_extensions')
->end()
->variableNode('default_limit')
->end()
->end();

return $treeBuilder;
}
}
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ XiSearchBundle:
prefix: /
```
### config.yml -file
```yml
xi_search:
result_renderer_extensions:
type: [type]_renderer_extension
default_limit: [50]
```
### extend ajaxForm (from ajaxbundle) and make sure you bind your custom class as your ajax form handler (see ajaxbundle documentation)
``` coffee
Expand Down

0 comments on commit 7f859cb

Please sign in to comment.