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

ENT8R notifications at github.com
Wed Oct 10 16:44:35 UTC 2018


ENT8R 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])

> and then using doing the user filter as `.joins(:comments).where(:note_comments => { :author => @user })`

Well, but there is no `author` existing in the table: https://github.com/openstreetmap/openstreetmap-website/blob/master/app/models/note_comment.rb#L9-L10 we can only search by `author_ip` or `author_id`... Is the latter one maybe achievable through `.joins(:comments).where(:note_comments => { :author_id => @user.id })`?

-- 
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_r224156276
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20181010/55d7171d/attachment-0001.html>


More information about the rails-dev mailing list