Plots2: Search API: endpoint /srch/nearbyPeople needs to sort by most recent users

Created on 22 Oct 2018  ·  3Comments  ·  Source: publiclab/plots2

As discussed here (Question: What more data-layers can we show on map?) I implemented (#3719) a new method to search nearby people with respect to given latitude, longitude and tag (optional).

Code is in here: https://github.com/publiclab/plots2/blob/master/app/services/search_service.rb#L118-L146

  def tagNearbyPeople(query, tag, limit = 10)
    raise("Must separate coordinates with ,") unless query.include? ","

    lat, lon =  query.split(',')

    user_locations = User.where('rusers.status <> 0')\
                         .joins(:user_tags)\
                         .where('value LIKE ?', 'lat:' + lat[0..lat.length - 2] + '%')\
                         .distinct
    if tag.present?
      user_locations = User.joins(:user_tags)\
                       .where('user_tags.value LIKE ?', tag)\
                       .where(id: user_locations.select("rusers.id"))
    end

    ids = user_locations.collect(&:id).uniq || []

    items = User.where('rusers.status <> 0').joins(:user_tags)
                .where('rusers.id IN (?) AND value LIKE ?', ids, 'lon:' + lon[0..lon.length - 2] + '%')

    # selects the items whose node_tags don't have the location:blurred tag
    items.select do |item|
      item.user_tags.none? do |user_tag|
        user_tag.name == "location:blurred"
      end
    end

    items = items.limit(limit)
  end

Now, as a next step we need to modify the method to sort the results by most recent sign up at least.

The search_profiles() method sorts the results by most recent users, I think the same strategy can be used here.

Ruby help wanted search

All 3 comments

Awesome !!!

@milaaraujo can I work on this?

Sure, just assign the issue to yourself!

Was this page helpful?
0 / 5 - 0 ratings