-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add an instant search (via AJAX) #173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Wow, it's cool! But I think it's a bit overhead for demo project. |
@voronkovich 👍 I like this idea a lot. Thanks for working on it. However, after a first quick review of the code, I find the |
@javiereguiluz, if we remove the |
7865f32
to
0f183f4
Compare
*/ | ||
public function searchAction(Request $request) | ||
{ | ||
$q = $request->query->get('q'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's avoid a 1 char variable name :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's vastly using name for a search request. The Symfony search uses this name http://api.symfony.com/2.7/index.html?q=request
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, variable's name is matching with input name, so I prefer to use $q
to be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, as an URL param, not a PHP variable
0f183f4
to
c3da6ee
Compare
I've renamed the |
return 2 <= strlen($term); | ||
}); | ||
|
||
$posts = new ArrayCollection(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be an array. Doctrine does not return collection objects when doing queries
Fixed. Thanks @stof! |
return; | ||
} | ||
|
||
addItemToPreview(item) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need a semicolon here to avoid issues in some browsers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no issue here. Browsers are consistent in the way they insert semi-colons
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Then I ask for this change because of our own code consistency. Either add this semicolon ... or remove all the other semicolons. Thanks!
}; | ||
|
||
var throttle = (function(){ | ||
var timer = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
your throttling function is flawed: it can be used only once as all usages of the throttle
function are sharing the same timer
Fixed again. Thanks, @stof! |
25d4be6
to
c4b943a
Compare
@voronkovich Seems like this needs a rebase. |
@xabbuh can you shortly explain what exactly I have to do with it? |
-1 on this implementation for now. We should not advocate |
OK then. Let's wait a bit to solve the XSS issues :) |
7a32167
to
a6a3192
Compare
Fixed! Thanks, @stof! |
a6a3192
to
c130256
Compare
f7098dc
to
c651e44
Compare
c651e44
to
f017bb2
Compare
@javiereguiluz, what about to merge this PR? |
6f700c1
to
d187dcd
Compare
176b753
to
3194067
Compare
3194067
to
f45c31c
Compare
This PR was merged into the master branch. Discussion ---------- Add an instant post search I've taken the code commitedd by @voronkovich in #173 and made some changes to it. Let's see if you like it. I propose to implement it like Google search results instead of displaying it in the main menu:  The reason is that the main menu is crowded when the user is logged in and the search bar looks bad. Commits ------- fe2e2ab Fixed CS issues 51ab96a Added missing search.js file f219db9 Changes requested by reviewers 0c236ed Refactored the feature da43022 Fix cs issues f45c31c Add an instant post search
$results = []; | ||
|
||
foreach ($posts as $post) { | ||
array_push($results, [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just $results[] = xxx
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We finally used $results[] = xxx
... mostly because PHPStorm displayed a pretty annoying message suggesting that 😄
It's almost like the Google... but better



