* fix auto-detection issues for movie query "9 (2009)"

This commit is contained in:
Reinhard Pointner 2015-09-27 08:41:02 +00:00
parent 052ba0e26f
commit 9ad9a3e1a9
2 changed files with 14 additions and 3 deletions

View File

@ -69,7 +69,7 @@ public class TMDbClient implements MovieIdentificationService {
@Override
public List<Movie> searchMovie(String query, Locale locale) throws IOException {
// query by name with year filter if possible
Matcher nameYear = Pattern.compile("(.+)\\b(19\\d{2}|20\\d{2})$").matcher(query);
Matcher nameYear = Pattern.compile("(.+)\\b\\(?(19\\d{2}|20\\d{2})\\)?$").matcher(query.trim());
if (nameYear.matches()) {
return searchMovie(nameYear.group(1).trim(), Integer.parseInt(nameYear.group(2)), locale, false);
} else {
@ -79,7 +79,7 @@ public class TMDbClient implements MovieIdentificationService {
public List<Movie> searchMovie(String movieName, int movieYear, Locale locale, boolean extendedInfo) throws IOException {
// ignore queries that are too short to yield good results
if (movieName.length() < 3 && !(movieName.length() > 1 && movieYear > 0)) {
if (movieName.length() < 3 && !(movieName.length() >= 1 && movieYear > 0)) {
return emptyList();
}

View File

@ -28,7 +28,7 @@ public class TMDbClientTest {
}
@Test
public void searchByNameWithYear() throws Exception {
public void searchByNameWithYearShortName() throws Exception {
List<Movie> result = tmdb.searchMovie("Up 2009", Locale.ENGLISH);
Movie movie = result.get(0);
@ -38,6 +38,17 @@ public class TMDbClientTest {
assertEquals(14160, movie.getTmdbId());
}
@Test
public void searchByNameWithYearNumberName() throws Exception {
List<Movie> result = tmdb.searchMovie("9 (2009)", Locale.ENGLISH);
Movie movie = result.get(0);
assertEquals("9", movie.getName());
assertEquals(2009, movie.getYear());
assertEquals(-1, movie.getImdbId());
assertEquals(12244, movie.getTmdbId());
}
@Test
public void searchByNameGermanResults() throws Exception {
List<Movie> result = tmdb.searchMovie("East of Eden", Locale.GERMAN);