-
Notifications
You must be signed in to change notification settings - Fork 189
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
Reduce amount of JSON sent from backend with query results #1221
Comments
Hello @humphd, if nobody takes this issue, can I try this? |
@StellaJung-Student The data is going to looks like this
What he's asking is to order these values by the score in descending order and then only take the top N (set by environment variable). |
I got it. However, for testing, do I need to sign up? I got this error, GET http://localhost:3000/auth/login 500. If yes, can you provide how I can sign up on local environment? I am a new for this project :) Do I need a docker as well? If I set the local environment, I can use DB data? After fixing it, I tried to test but no output. Actually, it was the same, when I forked and set up the project. |
You won't need to sign in for this, since we're using the search function of telescope. You can always just |
The response data is always 'text: '{"results":0,"values":[]}' even in previous test case, query.test.js. I can commit but I don't know how I can make sure my task is correct. |
Do you have the backend running at least? If you have it running natively you won't need docker. I would highly recommend docker though, as it is the easiest way to run everything in the backend. Let me know if you have other questions. Feel free to ask more questions on the slack channel in Telescope if you're still having issues |
@StellaJung-Student In the search page, you need to click on cc @c3ho |
I'm so blind. I forgot the search function changed. I remember I had either of the options set by default so this doesn't happen |
Oh my god, Thank you so much~ if you want me to add the validation or default value~ let me know~. :) |
Thank you both of you. I learned a lot from you guys~. I will take a look at this issue~ |
@StellaJung-Student I think you're thinking too much into this. Here's what I suggest in query.js line 26 let's break it off so we have something like
|
OK. I am not going to think too much. For sort, I need to use _score property but it is not allowed to use by the rule of no-unserscore-dangle. |
I don't think you need underscores as the code should look something like
|
I don't think this is a solution. @humphd mentioned removing the text field is the main purpose for this task and the score is only used for sorting. In the file, indexer.js, previously, it used _id, _text, _score so I tried to delete _text and with _score, tried to sort. |
No, you're right. That makes it a lot easier now then.
|
Oh, thanks~ you are right~ and it is better that if I use map first. But, if I want to remove score property, how can I do? do I run the map again to get only the ids array?
I want this
|
|
The basic object does not have score property, which is { _id, _text, _score } By the way how did you display your code well-organized? |
Of course it was working since the original code like this
The return value are changed to {id, text, score} from the {_id, _text, _score}. |
I don't even think you need to do sort, since the results are sorted already. You just need to remove the text and score from the |
Or even just: const values = hits.hits.map(({ _id }) => ({ id: _id })); So we spit back an array of |
@c3ho my original question is that I thought the score is only for sort value that's why I though I needed sort. @humphd In this case, I thought two options like below.
I want this
@humphd I know your solution. but that was not my question~ |
Yeah, the results we get back from es are already sorted, so we only have to remove |
OK. I see~ I didn't know the elastic search provide sorted data. |
…ts (#1253) * removed unused properties * added test codes * removed unused test cases * modified some values meaningfully * moved search test to feed.test
…query results (Seneca-CDOT#1253) * removed unused properties * added test codes * removed unused test cases * modified some values meaningfully * moved search test to feed.test
In #1217 I'm changing the way our search code works so that we only require a Post's
id
to show results. Let's modify how the backend/query
route and front-endSearchPage
work so that they don't send or require the raw text of the post. This will involve modifying how the data we get back from an Elasticserach query is formatted.Relevant files:
/query
route in the API server - https://github.com/Seneca-CDOT/telescope/blob/master/src/backend/web/routes/query.js/query
route - https://github.com/Seneca-CDOT/telescope/blob/master/test/query.test.jsSearchPage
component - https://github.com/Seneca-CDOT/telescope/blob/master/src/frontend/src/components/SearchPage/SearchPage.jsxRight now we return data that looks like this:
The
results
are how many matches were found, andvalues
is an array of matches on posts. Within these we getid
(which we want) and
text(which is huge and we don't need), and then
score` which may or may not be valuable, if we pre-sort on it so that the posts are already ordered by score.The text was updated successfully, but these errors were encountered: