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

added advanced search query for elasticsearch #2617

Merged

Conversation

AmasiaNalbandian
Copy link
Contributor

@AmasiaNalbandian AmasiaNalbandian commented Dec 15, 2021

Issue This PR Addresses

This PR closes #2110

Type of Change

  • Bugfix: Change which fixes an issue
  • New Feature: Change which adds functionality
  • Documentation Update: Change which improves documentation
  • UI: Change which improves UI

Description

This PR Is aimed to help make search queries more flexible. What I have done here is I looked into Elasticsearch so that we can further query different fields we have indexed in Posts. I looked at the data presented back by Elasticsearch and realized we have more fields we can use to search:

  • post
  • title
  • author
  • date published

This PR allows for us to query all of this on the backend, with search and Elasticsearch.

Additionally, this query seems to be more promising than the original query for the post/author search. We should eventually use the query provided here, as the zero_terms_query: 'all', means that if that field is not provided, to search without it. This means we can use this query to search for one, two, three... or all fields, acting the same way as the previous implementation but doing more. The query will also work if we want to search for all posts published on X date, or from x to y dates.

Steps to test:

  1. delete redis-data file if it exists
  2. cp config/env.development .env
  3. docker-compose --env-file ./config/env.development up --build search elasticsearch redis posts
  4. to rebuild search: docker-compose --env-file ./config/env.development up --build -d search posts (NOT Necessary - Skip! just FYI)
  5. in another terminal run pnpm start to start the feed parser. Wait a bit for some posts to populate.
  6. As the changes are only reflected in the API, you can test queries using such:
    http://localhost/v1/search/advanced/?post=elasticsearch&author=amasia
    feel free to add more filters such as author, title, from, to and post

After you are done ensure your containers are down by running docker-compose --env-file ./config/env.development down

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)
  • Documentation: This PR includes updated/added documentation to user exposed functionality or configuration variables are added/changed or an explanation of why it does not(if applicable)

Example of how the search works:

The screenshot is taken from elasticsearch on localhost:9200 for reference of the post:
chrome_eujzknH9TX

@gitpod-io
Copy link

gitpod-io bot commented Dec 15, 2021

@humphd
Copy link
Contributor

humphd commented Dec 15, 2021

This needs a proper description of what it is, what it changes, how to test it, etc.

@AmasiaNalbandian
Copy link
Contributor Author

This needs a proper description of what it is, what it changes, how to test it, etc.

This was not meant to be compared to Seneca Master... I am still cherry picking commits - sorry about this.

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 needs tests.

src/api/search/src/bin/validation.js Show resolved Hide resolved
src/api/search/src/bin/validation.js Outdated Show resolved Hide resolved
src/api/search/src/routes/query.js Show resolved Hide resolved
src/api/search/src/search.js Outdated Show resolved Hide resolved
src/api/search/src/bin/validation.js Outdated Show resolved Hide resolved
@AmasiaNalbandian
Copy link
Contributor Author

This needs tests.

Where can I find the tests to write for this? I know you've mentioned it a bunch of times... do we want to just test the routes?

@AmasiaNalbandian AmasiaNalbandian self-assigned this Dec 16, 2021
@humphd
Copy link
Contributor

humphd commented Dec 16, 2021

They should be in https://github.com/Seneca-CDOT/telescope/tree/master/src/api/search, but apparently we have no tests for this service? Please file an issue for us to add them, since they don't exist, and we'll do it all at once.

@AmasiaNalbandian
Copy link
Contributor Author

They should be in https://github.com/Seneca-CDOT/telescope/tree/master/src/api/search, but apparently we have no tests for this service? Please file an issue for us to add them, since they don't exist, and we'll do it all at once.

I've filed this: #2621

@humphd
Copy link
Contributor

humphd commented Dec 16, 2021

OK, so let's get my other comments addressed in updates and try to land this ASAP.

@AmasiaNalbandian
Copy link
Contributor Author

chrome_RWzZN27Wkp

Queries after requested changes

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.

Getting close, a few more things

},
};

const must = query.query.bool.must;
Copy link
Contributor

Choose a reason for hiding this comment

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

const { must } = query.query.bool;

* Match field queries: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-ppmatch-query.html#query-dsl-match-query-zero
*/
const advancedSearch = async (options) => {
const query = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets' name this result so we don't have query.query

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

humphd commented Jan 20, 2022

Let us know when this is ready for review.

added advanced route with params

separated query validation based on route pathname

cleaned up the files

added validation

cleaned up validator

added oneof in declarations

fixed validation

changed query fields and added if statements for options passed

changed description for advanced search

fixed date format to correct format
@AmasiaNalbandian
Copy link
Contributor Author

it is ready now! Thank you @JerryHue!
chrome_CEwLHrVK1V

@AmasiaNalbandian
Copy link
Contributor Author

I updated all the instructions if you want to build and try it out. :) But also for my own memory...

@TDDR TDDR requested review from menghif and HyperTHD January 20, 2022 13:15
Copy link
Contributor

@JerryHue JerryHue left a comment

Choose a reason for hiding this comment

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

Where can I find the build instructions?

@AmasiaNalbandian
Copy link
Contributor Author

Where can I find the build instructions?

It's in the PR Description. @JerryHue

Copy link
Contributor

@HyperTHD HyperTHD left a comment

Choose a reason for hiding this comment

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

Tested, works good. My only concern is the lack of tests but the search service doesn't have any tests at all. Might want to file a follow-up to get those added in unless that's been filed already

@AmasiaNalbandian
Copy link
Contributor Author

Tested, works good. My only concern is the lack of tests but the search service doesn't have any tests at all. Might want to file a follow-up to get those added in unless that's been filed already

It's been filed and assigned! :)

@HyperTHD
Copy link
Contributor

Just noticed #2621 so once you get another approval, you can rebase and merge this in @AmasiaNalbandian

@JerryHue JerryHue self-requested a review January 20, 2022 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: elasticsearch Elasticsearch Related issues and pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Advanced search dialog in SearchBar
4 participants