[openstreetmap/openstreetmap-website] Enhanced the notes search endpoint (#1955)

Tom Hughes notifications at github.com
Tue Oct 9 18:54:42 UTC 2018


tomhughes commented on this pull request.



> -    @notes = @notes.joins(:comments).where("to_tsvector('english', note_comments.body) @@ plainto_tsquery('english', ?)", params[:q])
+    if @user
+      @notes = @user.notes
+      @notes = closed_condition(@notes)
+    elsif params[:display_name] || params[:id]
+      # Return an error message because obviously the user could not be found
+      raise OSM::APIBadUserInput, "The user could not be found"
+    else
+      @notes = closed_condition(Note.all)
+    end
+
+    # Filter by a given string
+    if params[:q]
+      @notes = @notes.joins(:comments)
+      @notes = if @user
+                 @notes.where("to_tsvector('english', comments_notes.body) @@ plainto_tsquery('english', ?)", params[:q])

I definitely think there is a case for starting form `Note.all` and then using doing the user filter as `.joins(:comments).where(:note_comments => { :author => @user })` so that we can do this condition in one consistent way.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/1955#discussion_r223822348
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20181009/e89b40f5/attachment.html>


More information about the rails-dev mailing list