Skip to content
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

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

Closed
milaaraujo opened this issue Oct 22, 2018 · 3 comments
Closed
Labels
help wanted requires help by anyone willing to contribute Ruby search

Comments

@milaaraujo
Copy link
Collaborator

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.

@sagarpreet-chadha
Copy link
Contributor

Awesome !!!

@Nada1996
Copy link
Contributor

@milaaraujo can I work on this?

@milaaraujo
Copy link
Collaborator Author

Sure, just assign the issue to yourself!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted requires help by anyone willing to contribute Ruby search
Projects
None yet
Development

No branches or pull requests

3 participants