Ticket: Text and Subfield Search Genres cases

Hi, I need some help
I did

/**

  • Finds and returns movies matching a one or more genres.
  • @param {string} genre - The genres to match with.
  • @returns {QueryParams} The QueryParams for genre search
    /
    static genreSearchQuery(genre) {
    /
    *
    Ticket: Text and Subfield Search
Given an array of one or more genres, construct a query that searches
MongoDB for movies with that genre.
*/

const searchGenre = Array.isArray(genre) ? genre : genre.split(", ")

// TODO Ticket: Text and Subfield Search
// Construct a query that will search for the chosen genre.
const query = {genres: {$in: searchGenre}}
const project = {}
const sort = DEFAULT_SORT

return { query, project, sort }

}
For the test case with one genre
I got the right number of results but however I didn’t get “Gladiator” as the first movie

The same for the second
I got the right number of results but however I didn’t get “2 Fast 2 Furious” as the first movie

what could I do?

I am not too sure about

Print the values of the genre to make sure you split with the appropriate string. Yours will split (Horror, Comedi) with the space but not (Horror,Comedi) without the space.

Wrong title of first movie is probably more related to sorting than wrong splitting. So I would look where genreSearchQuery is used to make sure the sort value of the QueryParams is use appropriately.

1 Like