Skip to content

Commit f219db9

Browse files
committed
Changes requested by reviewers
1 parent 0c236ed commit f219db9

File tree

12 files changed

+434
-433
lines changed

12 files changed

+434
-433
lines changed

app/Resources/views/blog/search.html.twig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@
1515
<div id="results">
1616
</div>
1717
{% endblock %}
18+
19+
{% block sidebar %}
20+
{{ parent() }}
21+
22+
{{ show_source_code(_self) }}
23+
{% endblock %}

assets/js/search.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import './jquery.instantSearch.js';
22

33
$(function() {
4-
$('.search-field').instantSearch();
4+
$('.search-field').instantSearch({
5+
previewDelay: 100,
6+
});
57
});

assets/scss/app.scss

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,6 @@ header .locales a {
6767
padding-right: 10px
6868
}
6969

70-
header .search-bar {
71-
padding: 0.8em 0;
72-
}
73-
74-
header .search-bar form {
75-
position: relative;
76-
}
77-
78-
header .search-preview {
79-
position: absolute;
80-
width: 100%;
81-
top: 100%;
82-
}
83-
8470
.body-container {
8571
flex: 1;
8672
/* needed to prevent pages with a very small height and browsers not supporting flex */

src/AppBundle/Controller/BlogController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function commentFormAction(Post $post)
156156
* @Route("/search", name="blog_search")
157157
* @Method("GET")
158158
*
159-
* @return JsonResponse
159+
* @return Response|JsonResponse
160160
*/
161161
public function searchAction(Request $request)
162162
{
@@ -176,6 +176,6 @@ public function searchAction(Request $request)
176176
];
177177
}
178178

179-
return new JsonResponse($results);
179+
return $this->json($results);
180180
}
181181
}

src/AppBundle/Repository/PostRepository.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,24 @@ private function createPaginator(Query $query, $page)
6060
return $paginator;
6161
}
6262

63+
/**
64+
* @param string $rawQuery The search query as input by the user
65+
* @param int $limit The maximum number of results returned
66+
*
67+
* @return array
68+
*/
6369
public function findBySearchQuery($rawQuery, $limit = Post::NUM_ITEMS)
6470
{
6571
$query = $this->sanitizeSearchQuery($rawQuery);
66-
$terms = $this->extractSearchTerms($query);
72+
$searchTerms = $this->extractSearchTerms($query);
6773

68-
if (empty($terms)) {
74+
if (0 === count($searchTerms)) {
6975
return [];
7076
}
7177

7278
$queryBuilder = $this->createQueryBuilder('p');
7379

74-
foreach ($terms as $key => $term) {
80+
foreach ($searchTerms as $key => $term) {
7581
$queryBuilder
7682
->orWhere('p.title LIKE :t_'.$key)
7783
->setParameter('t_'.$key, '%'.$term.'%')
@@ -85,14 +91,20 @@ public function findBySearchQuery($rawQuery, $limit = Post::NUM_ITEMS)
8591
->getResult();
8692
}
8793

94+
/**
95+
* Removes all non-alphanumeric characters except whitespaces
96+
*
97+
* @param string $query
98+
*
99+
* @return string
100+
*/
88101
private function sanitizeSearchQuery($query)
89102
{
90-
// remove all non-alphanumeric characters except whitespaces
91103
return preg_replace('/[^[:alnum:] ]/', '', trim(preg_replace('/[[:space:]]+/', ' ', $query)));
92104
}
93105

94106
/**
95-
* Splits the query into terms and removes the ones which are too short.
107+
* Splits the search query into terms and removes the ones which are irrelevant.
96108
*
97109
* @param string $query
98110
*

web/build/css/app.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/build/js/admin.js

Lines changed: 379 additions & 379 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/build/js/app.js

Lines changed: 17 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/build/js/common.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/build/js/login.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
webpackJsonp([5],{nxx7:/*!****************************!*\
1+
webpackJsonp([6],{137:/*!****************************!*\
22
!*** ./assets/js/login.js ***!
33
\****************************/
4-
function(n,a,l){(function(n){n(function(){var a=n("#username"),l=n("#password");a.val()||l.val()||(a.val("jane_admin"),l.val("kitten"))})}).call(a,l(/*! jquery */"7t+N"))}},["nxx7"]);
4+
function(a,n,l){(function(a){a(function(){var n=a("#username"),l=a("#password");n.val()||l.val()||(n.val("jane_admin"),l.val("kitten"))})}).call(n,l(/*! jquery */1))}},[137]);

web/build/manifest.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/build/manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@
2323
"build/js/app.js": "/build/js/app.js",
2424
"build/js/common.js": "/build/js/common.js",
2525
"build/js/login.js": "/build/js/login.js",
26+
"build/js/search.js": "/build/js/search.js",
2627
"build/manifest.js": "/build/manifest.js"
2728
}

0 commit comments

Comments
 (0)