Ticket: genreSearchQuery

Hello everyone,

I am having some issues with trying to implement the search functionality for the genreSearchQuery method.

When I run npm test -t text-subfield this is what is returned in my console:

Determining test suites to run...Setup Mongo Connection
 PASS  test/text-subfield.test.js
  Text and Subfield Search
    ✓ Can perform a text search (298ms)
    ✓ Can perform a genre search with one genre (297ms)
    ✓ Can perform a genre search with multiple genres (195ms)
    ✓ Can perform a cast search with one cast member (315ms)
    ✓ Can perform a cast search with multiple cast members (239ms)
    ✓ Can perform a search and return a non-default number of movies per page (243ms)

Test Suites: 1 passed, 1 total
Tests:       6 passed, 6 total
Snapshots:   0 total
Time:        2.933s, estimated 4s
Ran all test suites matching /text-subfield/i.
Teardown Mongo Connection

…and when I search for one genre via the UI, I am getting a status code of success/200 (and the UI returns the movies that fall under the genre ‘Action’):

GET /api/v1/movies/search?genre=Action 200 306.855 ms - 42201

I also get a status of 200 when I attempt to search for more than one genre, but the UI just freezes and fails to return anything at all:

GET /api/v1/movies/search?genre=Action,%20Thriller 200 176.922 ms - 101

Could anyone give me a hint as to why this might be happening?

Thanks in advance:-)

This is most likely not an issue on your end. Can you refresh the application or does it hard freeze?

I’ll investigate this in the source to see what might be happening.

Hi Nathan,

Thank you for responding so quickly!

I am able to refresh the application, though I am now noticing that sometimes I am getting a 304 response on page refresh (…not sure if this is related to caching, but I assume that it is):

GET /api/v1/movies/ 304 310.518 ms - -

Thanks:-)

PS. If I open a new (private) window, the response goes back to 200…still though, no return of a movies array if I search for multiple genres…just a spinner that spins in perpetuity :smiley:

Thanks for the update. I haven’t had a chance to look into the UI yet but it’s in my queue!

To force a full refresh, the keyboard shortcut (I believe) is cmd/ctrl-shift-r if you’d rather do that than open an incog window.

1 Like

Thanks for the refresh tip!

I do have one last question:

If all of the tests are passing via the npm test -t text-subfield, should I assume that my code is indeed correct? I’m afraid to submit an answer just yet.

Cheers:-)

Hi All,

I have got a question on this topic as well.

The test for ... search with multiple genres is failing as totalNumMovies is not equal expected number.

querying via command line return count as 7259

MongoDB Enterprise mflix-shard-0:PRIMARY> db.movies.count({'genres' : { $in: ['Mystery','Thriller']}}) 7259

However the status page shows Text and Subfield Search as completed and allows to copy the code. Not sure what causing this behaviour, hope someone can advice.

Have re-imported mflix database couple of times now, the total document in movies collection is always 45993.

finished restoring mflix.movies (45993 documents)

Thanks!

alexander@apbox:~/www/m220/mflix-js$ npm test -t text-subfield

> server@1.0.0 test /home/alexander/www/m220/mflix-js
> jest --passWithNoTests "text-subfield"

Determining test suites to run...Setup Mongo Connection

 FAIL  test/text-subfield.test.js
  Text and Subfield Search
    ✓ Can perform a text search (105ms)
    ✓ Can perform a genre search with one genre (120ms)
    ✕ Can perform a genre search with multiple genres (99ms)
    ✓ Can perform a cast search with one cast member (237ms)
    ✓ Can perform a cast search with multiple cast members (138ms)
    ✓ Can perform a search and return a non-default number of movies per page (153ms)

  ● Text and Subfield Search › Can perform a genre search with multiple genres

    expect(received).toEqual(expected)

    Expected value to equal:
      7261
    Received:
      7259

      34 |     })
      35 |     expect(moviesList.length).toEqual(20)
    > 36 |     expect(totalNumMovies).toEqual(7261)
         |                            ^
      37 |     const firstMovie = moviesList[0]
      38 |     expect(firstMovie["title"]).toEqual("2 Fast 2 Furious")
      39 |   })

      at toEqual (test/text-subfield.test.js:36:28)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:296:22)
      at Generator.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:114:21)
      at step (node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
      at node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13

Test Suites: 1 failed, 1 total
Tests:       1 failed, 5 passed, 6 total
Snapshots:   0 total
Time:        1.472s, estimated 2s
Ran all test suites matching /text-subfield/i.
Teardown Mongo Connection
npm ERR! Test failed.  See above for more details.

Hi @alexpechkarev,

I too ran the same query via the command line and also received a return count of 7259. When I do a find/count on mflix.movies I also get 45993 as a document count.

I changed the totalNumMovies (thinking that this is what I’m supposed to do) like so:

expect(totalNumMovies).toEqual(7259)

…then all of the tests pass…

I realize that this doesn’t help you much.

Maybe we’ll get a hint soon.

Cheers:-)

I have the same problem. My test pass but , the search in the app freezes.

Request:

image

I get the following response:

{“movies”: ,“page”:0,“filters”:{“genre”:“Action”},“entries_per_page”:20,“total_results”:0}

Many thanks @juliettet!

It makes sense now, I did change the test file too, to match the response from query request to get all tests green.

The status page shows the Text and Subfield Search test as complete as long as I had the query in genreSearchQuery method, irrespectively if the test passed or not.

Regards

Hello everyone. When I try to run most of the tests I get the following error
Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.

Thanks in advance :smiley:

Hi, I think you use old Handouts data, mflix-js.zip yesterday was replaced :japanese_ogre:

1 Like

Thank you… Ill try updating my files

So i did redownload the data and exported to cluster. I am getting

✓ Can perform a country search for one country (179ms)
✕ Can perform a country search for three countries (5009ms)

● Projection › Can perform a country search for three countries

Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.

I want to know whether the issue is my projection or something else. Thank you.

I can only guess given the information but I’m leaning towards an implementation issue on your end. You can DM your code to avoid spoilers for others and we can look over it.

I will do that. So how does one dm? I am on mobile. Thank you.

@nathan.leniz
As far as the UI spinning out when trying to search multiples.Just assuming here but looking at the code, the assertions pass because an array is passed to the test so everything works as expected. The code itself however even in the predefined functions the parameter is checked to see if it is in array however if it isn’t calling Array() doesn’t correctly splice the query into pieces and the UI doesn’t have any specifics about how to enter multiples. I just added a small function to top of class and made an ugly assumption that the input coming in from the UI is comma delimited since some genres could theoretically contain spaces and make it a bad idea to split on.

So added the following to top of class declaration

  • static getArrayFromQuery(query){return query.split(’,’);}

And changed the following line

  • const searchGenre = Array.isArray(genre) ? genre : Array(genre);
    to

  • const searchGenre = Array.isArray(genre) ? genre : this.getArrayFromQuery(genre);

let everything work as expected but im sure it can done more elegantly lol.

2 Likes

Thanks for digging into this! I’ve not had time to look into it yet, but I have a good place to start now :slight_smile:

We’ll definitely have this fixed for the next offering of the course. We try not to release updates to the UI mid-course as it can be incredibly disruptive.

1 Like

Thanks @imareo!
I have reload the data last night, but will give a go later on tonight as well.

Regards

This was the solution for my headache -.- Thank you!!

Hi Nathan

I have a similar issue related to text and subfield search . Even afer spending lot of time and effort i couldn’t generate the code . My test are passed and not sure why status page is not showing the code.

Please take a look .