Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Movie: Check movie year against searched year #1340

Merged
merged 5 commits into from Jan 29, 2015
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion share/spice/movie/movie.js
Expand Up @@ -28,6 +28,20 @@
source = $(script).attr("src"),
query = source.match(/movie\/([^\/]+)/)[1];

//Check if the query contains a year
var year = decodeURIComponent(query).match(/\d{4}/gm),
Copy link
Member

Choose a reason for hiding this comment

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

Might want to but \b around the capture? Otherwise it'll capture 4 digits as a substring. Should probably also check that the year is a valid, ie. > 1900 and maybe < current year + 5 (to look for upcoming movies)?

singleResult = [];

if(year) {
$.each(api_result.movies, function(key, result) {
//Check movie year and title against query
if(result.year == year && decodeURIComponent(query).replace(/\d{4}/,'').trim() == result.title.toLowerCase()) {
Copy link
Member

Choose a reason for hiding this comment

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

What if the year is part of the movie? It's largely an edge case but I know "Death Race 2000" and "2001: A Space Odyssey" would fall into that category. -- We might need to check if the result movie title has a year and compare it to what we detected in which case it's likely the year is part of the title and not specifying a release date

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Easy! I'll add a check.

singleResult.push(result);
}
});
if(singleResult.length>0) {api_result.movies = singleResult;}
Copy link
Member

Choose a reason for hiding this comment

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

I'm not entirely sure, but you may be able to move the comparison logic into normalize and use exactMatch/boost to specify the best result. Details: https://duck.co/duckduckhack/spice_displaying#exactmatch-codebooleancode-amp-boost-codebooleancode

It's intended for tile views, but I think in this case it would force the displayed result to be whatever the exactMatch or boost item is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like these properties will change the order of the items. Not sure it will work for displaying a single exact match. I'll definitely play around with these properties and see what happens 😄

}

Spice.add({
id: 'movie',
name: 'Movies',
Expand All @@ -38,7 +52,6 @@
itemType: 'Movies'
},
normalize: function(item) {

// Modify the image from _tmb.jpg to _det.jpg
var image = toDetail(item.posters.detailed);
return {
Expand Down