Ticket: text and subfield search

This is my code " query = {‘genres’: {"$in": filters[‘genres’]}} ", it not working.

It works, you only have to wait a long time till it validates.

Question is, why do you feel that it’s not working?

Are there errors shown in the web interface? Are there errors on the web server log? Are the results not as expected?

I also have same problem. I have waited for around 2 hours but still getting currently validating. Don’t know what is the problems here.

Yeah that’s a problem then. So, what else does the app show you?

What happens when you use the search to find items that should match your query? Does the Python console show any messages? It should always show that it received your query. Start troubleshooting and searching for output.

@Tess_Sluijter I will debug it and try to find out the issue. I will update you about debugging information after completing my debugging.

Check quotation marks from query you copied. They may not be single quotation marks.

Test do validate with the query, but I am not getting the desired results in UI with multiple genres search. I am very new to python and trying to understand what can be the troubleshooting steps in python application. get_movies function has query object being created in build_query_sort_project function.

I think the query that will be generated for the mongod should be - db.movies.find({“genres”:{$in: [‘Action’, ‘Adventure’]}},{“title”:1, genres:1,"_id":0})

Is there is a way to validate that in application logs ?

If you did that, the query would always only return movies that are Action or Adventure categories. You would never be able to search for anything else.

Not really… The application logs will show you if the query crashes due to syntax, but the only way to verify that it’s doing what you really want is by testing the application. You can use the validation script for it, but of course you can also test it manually yourself. I mean, say for example that you’re looking for Romance, expecting to see “Romeo and Juliet”, but instead you see Shrek? Well, that should be a hint :wink:

Thanks Tess. I updated the query variable in build_query_sort_project() function with query = {“genres”: {"$in": filters[‘genres’]}}. When I pass the Romance from front-end with genre filter, I do get Titanic, American Pie & Meet the Fockers on the first page, but when I pass Romance, Action, page doesn’t refresh with results. Though when I run the query from Mongo Shell, I get the results. Can I assume that the API layer is not sending the query params as [‘Romance’, ‘Action’] for multiple genres search ?

MongoDB Enterprise mflix-shard-0:PRIMARY> db.movies.find({genres:{$in:[‘Romance’, ‘Action’]}}, {title: 1, _id: 0, genres: 1} )

{ “title” : “Racket Girls”, “genres” : [ “Action”, “Crime”, “Drama” ] }

{ “title” : “Mighty Jack”, “genres” : [ “Action”, “Sci-Fi” ] }

{ “title” : “Pocket Ninjas”, “genres” : [ “Action”, “Family” ] }

{ “title” : “Pocket Ninjas”, “genres” : [ “Action”, “Family” ] }

{ “title” : “AVH: Alien vs. Hunter”, “genres” : [ “Action”, “Horror”, “Sci-Fi” ] }

{ “title” : “Five the Hard Way”, “genres” : [ “Action”, “Sport” ] }

{ “title” : “Titanic II”, “genres” : [ “Action”, “Adventure” ] }

{ “title” : “Atlantic Rim”, “genres” : [ “Action”, “Sci-Fi” ] }

1 Like

a) curl localhost:5000/api/v1/movies/search?genre=Action
“page”: 0,
“total_results”: 5917

b) curl localhost:5000/api/v1/movies/search?genre=Adventure
“page”: 0,
“total_results”: 4038

c) curl localhost:5000/api/v1/movies/search?genre=Action,Adventure
“entries_per_page”: 20,
“filters”: {
“genre”: [
“movies”: ,
“page”: 0,
“total_results”: 0

Please suggest, how can I get the correct results in the UI for multiple genres.

You will need to find something in the code that contains all the genres passed through the search. In the countries-exercise you did almost literally the same: there’s an array you need and which you can directly use in the query.