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

Implement Author Autocomplete (legacy backend and Search) #3301

Merged
merged 1 commit into from
Mar 25, 2022

Conversation

RC-Lee
Copy link
Contributor

@RC-Lee RC-Lee commented Mar 24, 2022

  • Add author autocomplete settings for indexer.js in backend
  • refactor Search service to work with new indexing
  • create new search query for author autocomplete
  • add supertest as a dev-dependency to pass ESLint

Issue This PR Addresses

Fixes #1417
also a part of issue #3225 (no new tests are added just yet)

Type of Change

  • New Feature: Change which adds functionality

Description

  • In the legacy backend, I've added settings and mapping for the posts index to use edge n-gram for author autocomplete
  • Because we couldn't specify type on index creation, I've refactored the Search service and tests to work with the new indexing. The current search query is not affected by this new change. pnpm test search would pass all tests.
  • To get author autocomplete suggestions, I've created a new query out of Search, and ways to test it and see it in action is as follows

Steps to test the PR

  • get on my branch, pnpm install
  • **Important** remove redis cache rm -rf redis-data, this is so the posts can be re-indexed
  • build Docker Images
 docker-compose --env-file ./config/env.development up --build redis elasticsearch posts traefik search nginx planet
  • Wait for a bit for ElasticSearch to connect, then pnpm start
  • Wait a bit for the posts to be indexed
  • Can now test Search queries at http://localhost/v1/search
  • The original Search queries shouldn't be affected. The new query can be tested at http://localhost/v1/search/authors/autocomplete/
  • When author is queried, it will return the number of suggested authors, and an array of suggested authors. As the query gets longer, results will be more precise

image
image
image
image
image

Problems

There is still a lot of tweaking that can be done

  • A strict validation for the http://localhost/v1/search/authors/autocomplete/ isn't yet in place. Currently I am only hijacking the old search validation. If we don't have an author query and it passes validation, we'll get a Error 400
    image
  • A query of only one letter won't pass validation, it has to be 2 or more letters. This is part of our rules in validation.js
    image

Checklist

  • Quality: This PR builds and passes our npm test and works locally
  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Screenshots: This PR includes screenshots or GIFs of the changes made or an explanation of why it does not (if applicable)variables are added/changed or an explanation of why it does not(if applicable)

@gitpod-io
Copy link

gitpod-io bot commented Mar 24, 2022

Copy link
Contributor

@humphd humphd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is amazing! I've done one read through, and will spend more time on it tomorrow, but it looks fantastic.

We should figure out if we can migrate this to the parser service, since it's landing soon (can happen in follow-up).

src/api/search/src/routes/query.js Outdated Show resolved Hide resolved
@RC-Lee
Copy link
Contributor Author

RC-Lee commented Mar 24, 2022

I've changed the route name, and I've also added highlights
ElasticSearch can help us wrap the searched terms with <em>...</em> tags. Which might be useful for the front end.
So we can decide if we want to keep one of authors and highlights or both

(I tested without waiting for all feeds to put in)
image

src/api/search/src/routes/query.js Show resolved Hide resolved
src/api/search/src/search.js Show resolved Hide resolved
src/api/search/src/search.js Show resolved Hide resolved
src/api/search/src/search.js Outdated Show resolved Hide resolved
src/backend/utils/indexer.js Show resolved Hide resolved
Copy link
Contributor

@DukeManh DukeManh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Google should consider hiring us.

src/api/search/src/search.js Outdated Show resolved Hide resolved
src/api/search/src/search.js Outdated Show resolved Hide resolved
Copy link
Contributor

@TueeNguyen TueeNguyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to spend some time learning on Edge n gram which was very interesting.
I tried to test this PR, the server ran but I couldn't to get any result back.

* http://localhost/v1/search/complete/?author=Da returns 404
* http://localhost/v1/search/authors/autocomplete/?author=Da returns 404

Edit: my backend took a while to index for some reason

Also the query looks strange, should it be http://localhost/v1/search/autocomplete?author=Da

@DukeManh
Copy link
Contributor

tried to test this PR, the server ran but I couldn't to get any result back.

The URL changed to http://localhost/v1/search/authors/autocomplete/?author=dav.

@Kevan-Y
Copy link
Contributor

Kevan-Y commented Mar 24, 2022

tried to test this PR, the server ran but I couldn't to get any result back.

The URL changed to http://localhost/v1/search/authors/autocomplete/?author=dav.

I think it would be better to have http://localhost/v1/search/authors/autocomplete?author=dav

@TueeNguyen
Copy link
Contributor

Yeah agree, the endpoint should look like autrocomplete?author=dav instead of /?author=dav

@Kevan-Y
Copy link
Contributor

Kevan-Y commented Mar 25, 2022

http://localhost/v1/search/authors/autocomplete/?author=dav

@TueeNguyen , That interesting how the routing works, http://localhost/v1/search/authors/autocomplete/?author=dav and http://localhost/v1/search/authors/autocomplete?author=dav are the same

@TueeNguyen
Copy link
Contributor

I think whatever is after the ? counts as query parameter.

@RC-Lee
Copy link
Contributor Author

RC-Lee commented Mar 25, 2022

Added comments
Added new author validation rule
Merged author and highlight

Copy link
Contributor

@humphd humphd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it.

*/
const validateQuery = () => {
return async (req, res, next) => {
await Promise.all(ValidationRules.map((rule) => rule.run(req)));
const rules = req.route.path === '/' ? ValidationRules : authorRules;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me nervous, but let's go with it for now and fix later. I'd rather split these routes up vs. having this logic determine what we do.

src/api/search/src/search.js Show resolved Hide resolved
src/api/search/src/search.js Show resolved Hide resolved
Copy link
Contributor

@Kevan-Y Kevan-Y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tested locally it works. Great feature @rclee91

- Add author autocomplete settings for indexer.js in backend
- refactor Search service to work wwith new indexing
- create /authors/autocomplete search query for author autocomplete
- add search term highlights
- add comments
- create new validation rules for author autocomplete
@JerryHue JerryHue merged commit 9875dcb into Seneca-CDOT:master Mar 25, 2022
@JerryHue JerryHue added this to the 2.9 Release milestone Mar 25, 2022
@RC-Lee RC-Lee deleted the author-autocomplete branch April 7, 2022 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add author suggestions to Elasticsearch indexer backend
6 participants