-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Improve textSearch_profiles result #3134
Improve textSearch_profiles result #3134
Conversation
Moved from #3126Hey @jywarren, I implemented a new version of profiles endpoint following your idea. If we call |
Generated by 🚫 Danger |
Hey @jywarren, regarding your question from the other PR (# 3126):
I created a silly test to illustrate the difference between the two ways of using the
|
3970a28
to
6c6c84a
Compare
Looks like a good moment to address this optimization issue too! #3147 |
app/services/search_service.rb
Outdated
def getRecentProfiles | ||
sresult = DocList.new | ||
|
||
nodes = Node.all.order("changed DESC").limit(100).distinct |
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.
I'm a little worried about the speed of this query. Could we collect up the uid
s, then run:
User.find_by(uid: uids.uniq).where(status: 1)
Then, we may also want to get recent edits, so what if we instead of doing Node
, we searched Revision
- that way we get both notes and wiki revisions?
app/services/search_service.rb
Outdated
users = SrchScope.find_users(srchString, limit = nil) | ||
users = | ||
if order == "recentdesc" | ||
filterMatchingUserName(getRecentProfiles, srchString) |
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.
Here, I worry we might not get any results if we filter after selecting the most recent 100. Is there another way to do this, like finding matching usernames first, sorting by last activity using the user table -- i think there's a last activity column, but not sure when we update that...
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 might take some kind of clever join
and group
query, like, joining revisions to the node table, and sorting by the revision timestamp...
Hi, sorry, we've created a conflict while fixing #3148 - but it should be pretty easy to resolve. Thanks! |
@jywarren agree with your comments! we will talk with our coaches today to help us improve the query, will keep you updated! |
c01cae5
to
45ccc31
Compare
@jywarren we started doing the sorting and ordering today, still need to work on some things, but we believe we are targeting your concerns on them. We are passing the a The approach that our coaches are suggesting us to so is searching the profiles, joining them with nodes and then ordering them by the latest activities (ASC or DESC). |
45ccc31
to
90603f5
Compare
hi @jywarren could you review here, please? We worked today on improving the We will work on the |
Great! First, looks like a missing or extra "end" in this file?
Reading now... |
app/services/search_service.rb
Outdated
|
||
if search_criteria.order_by == "recent" | ||
user_scope = user_scope.joins(:revisions)\ | ||
.order("timestamp #{search_criteria.sort_direction}")\ |
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.
I guess i have a couple thoughts here. In general, I think it's best not to be adding activeRecord filters or conditions to an object that's had them added at an earlier level of abstraction (like, within SrchScope.find_users), because you can't see them when you're editing, so there's a strong possibility of doing things redundantly or in conflict. Better to do all your ActiveRecord stuff in one place as much as possible.
Second, I wonder if there's a way to reduce the # of levels of abstraction. Here it seems like we do:
- A call arrives at
app/api/srch/search.rb
forget :profiles do
- its sent to
app/services/execute_search.rb
forexecute()
- that's sent to
app/services/search_service.rb
fortextSearch_profiles()
- that's sent to
app/services/srch_scope.rb
forSrchScope.find_users()
- finally an ActiveRecord call is made:
User.search()...
Each file is now much more readable, but tracing the whole thing is a bit harder. The readability improvements are super, and the files are cleaner and less redundant. Great work! Now, I wonder if we could try flattening the system without losing those advantages? One way to try (and we must admit it's possible every layer is important! But let's try.) is to list why each layer is needed.
- where incoming calls get routed
- utility 'execute' function
- back-end standard service available inside the app
- scope?
- do the ActiveRecord call
I'm not saying there is an obvious or easy answer here. And if we stick with 5 layers, that's fine! But this is how I'd recommend we look at the question of "what complexity is necessary" and how readable it is. Make sense? What do you think?
To your narrower question of the optimization, I think it makes sense that you're doing an initial call for users, then making a more complex version of it by joining revisions and then sorting using that new joined table. This looks great! Because the incoming query is already going to be pretty efficient, we think, and then we're just joining something and adding an ordering. How do you like the results it returns?
04a9b81
to
d210f2d
Compare
As to this, I think it's not a meaningful difference, although originally i think the idea was that it would return some representation of a tag or topic, while |
I'm going to open a new PR to get Travis to run against the with-bio version of |
on travis it works only with bio... so you need to pass a username as the param to see the errors. For example, if you pass "jeff" it returns nil, but if you pass "something interesting about jeff" it returns something. At least that's how it was before |
okay, about the meeting, tomorrow we can all attend at 5:00 pm EET, so can we confirm your -virtual- presence? :) |
Wait, i'm sorry -- does that mean Eastern European Time?
https://www.worldtimebuddy.com/?qm=1&lid=5,13,5128581&h=5&date=2018-8-10&sln=10-10.5
If so, that would be fine. I'm sorry, I had thought ET (eastern time).
Thanks!
…On Thu, Aug 9, 2018 at 4:38 PM Stefanni ***@***.***> wrote:
okay, about the meeting, tomorrow, Friday *August 10th 5:00 pm EET*,
then? :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3134 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJzySLis_ljjSv7CygW0CYCmd-H0Uks5uPJ25gaJpZM4VcGMQ>
.
|
I think i have an idea about searching for "jeff"... hang on...did it happen only for "jeff" or also for "steff"? Do you think you could try to reproduce the Travis error in a separate PR? Or was it exactly the error we're seeing here: #3224 ? |
And was the error you saw in |
yes, it's Eastern European Time! So, tomorrow 5:30 EET. See you there! |
great, thanks.
…On Thu, Aug 9, 2018 at 5:05 PM Stefanni ***@***.***> wrote:
yes, it's Eastern European Time! So, tomorrow 5:30 EET. See you there!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3134 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ0BkUU3YVcYaMEB259K6-1HzWMTvks5uPKP1gaJpZM4VcGMQ>
.
|
d42a395
to
10441b4
Compare
10441b4
to
42c5e32
Compare
OK, I modified the test PR at #3224 to build on your latest commits from this PR, and see what the issue was with the nil results. But I see you've modified to go back to Can you give me an update and I am happy to check in on it once I land.. it'll be sometime tomorrow If it's ready to go, I approve and can merge it! |
Hi, @jywarren thanks for the approval and for the help! Saturday we were able to make it work searching for username and bio!! You can try now with our last commit if you want to check it out too! We don't know exactly where things started going wrong. I guess the errors that Travis was showing confused us and we missed something small and everything became a snowball of errors... Yeah, I agree that it's better to create a new PR for the autocomplete feature, will start now! So... I can't believe I'm saying this, LOL, but yes this can be merged!! 🎉 thank you!! |
@@ -42,7 +43,7 @@ class User < ActiveRecord::Base | |||
after_destroy :destroy_drupal_user | |||
|
|||
def self.search(query) | |||
User.where('MATCH(username, bio) AGAINST(?)', query) | |||
User.where('MATCH(bio, username) AGAINST(? IN BOOLEAN MODE)', query + '*') |
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.
@jywarren gold lesson from this PR about the MySQL fulltext search: the 'IN BOOLEAN MODE' modifier with the * wildcard.
https://dev.mysql.com/doc/refman/8.0/en/fulltext-boolean.html
really glad that this is working now, thanks for the help!
Congratulations!!! 👍🏼⚡⚡ |
* Version 1: implementing new version of profiles endpoint and fixing recentPeople endpoint * Code climate * Code climate * Code climate [2] * Code climate [3] * Code climate [4] * Refactoring getRecentProfiles method * fixing order_by X sort_by * Trying to fix travis error * trying to fix travis again * using find_users * Fix User.search query * Fixing conflict * Giving better names for the methods * Hacking travis
Hey everyone!
We are opening this request to fix the issue #3069.
recentprofiles
that returns the profiles with most recent activity.recentPeople
method. In one of our latest PR (Remove API Search endpoints duplication #3045) we did the following change that was not correct. Because in this part of the code the limit is for the node search. So we undid this change and added a count to control the number of profiles returned (line 290).recentPeople
method is appropriate for thepeopleLocations
endpoint, since the method returns the location of people with most recent activity with a specific tag. Can we change it topeopleLocations
? So maybe we can userecentPeople
for our new method.We would like some feedback about our strategy here, thank you! :)
fixes #3069
@publiclab/reviewers @publiclab/soc @jywarren