@Test public void shouldLimitQueryLengthWhenAddingForbiddenWords() throws Exception { SearchRequest request = new SearchRequest(SearchSource.INTERNAL, SearchType.SEARCH, 0, 100); request.getInternalData().setForbiddenWords(Arrays.asList("characters50sssssssssssssssssssssssssssssssssssss1", "characters50sssssssssssssssssssssssssssssssssssss2", "characters50sssssssssssssssssssssssssssssssssssss3", "characters50sssssssssssssssssssssssssssssssssssss4", "characters40ssssssssssssssssssssssssssss", "aaaaa", "bbbbb")); String query = testee.addForbiddenWords(request, ""); assertThat(query.length()).isLessThan(255); }
protected String addForbiddenWords(SearchRequest searchRequest, String query) { List<String> allForbiddenWords = new ArrayList<>(searchRequest.getInternalData().getForbiddenWords()); allForbiddenWords.addAll(configProvider.getBaseConfig().getSearching().getForbiddenWords()); allForbiddenWords.addAll(searchRequest.getCategory().getForbiddenWords()); List<String> allPossibleForbiddenWords = allForbiddenWords.stream().filter(x -> !(x.contains(" ") || x.contains("-") || x.contains("."))).collect(Collectors.toList()); if (allForbiddenWords.size() > allPossibleForbiddenWords.size()) { logger.debug("Not using some forbidden words in query because characters forbidden by newznab are contained"); } if (!allPossibleForbiddenWords.isEmpty()) { StringBuilder queryBuilder = new StringBuilder(query); for (String word : allForbiddenWords) { if ((queryBuilder + " --" + word).length() < 255) { queryBuilder.append(" --").append(word); } } query = queryBuilder.toString(); } return query; }
NzbsOrg extends Newznab { protected String addForbiddenWords(SearchRequest searchRequest, String query) { List<String> allForbiddenWords = new ArrayList<>(searchRequest.getInternalData().getForbiddenWords()); allForbiddenWords.addAll(configProvider.getBaseConfig().getSearching().getForbiddenWords()); allForbiddenWords.addAll(searchRequest.getCategory().getForbiddenWords()); List<String> allPossibleForbiddenWords = allForbiddenWords.stream().filter(x -> !(x.contains(" ") || x.contains("-") || x.contains("."))).collect(Collectors.toList()); if (allForbiddenWords.size() > allPossibleForbiddenWords.size()) { logger.debug("Not using some forbidden words in query because characters forbidden by newznab are contained"); } if (!allPossibleForbiddenWords.isEmpty()) { StringBuilder queryBuilder = new StringBuilder(query); for (String word : allForbiddenWords) { if ((queryBuilder + " --" + word).length() < 255) { queryBuilder.append(" --").append(word); } } query = queryBuilder.toString(); } return query; } }
NzbsOrg extends Newznab { protected String addForbiddenWords(SearchRequest searchRequest, String query) { List<String> allForbiddenWords = new ArrayList<>(searchRequest.getInternalData().getForbiddenWords()); allForbiddenWords.addAll(configProvider.getBaseConfig().getSearching().getForbiddenWords()); allForbiddenWords.addAll(searchRequest.getCategory().getForbiddenWords()); List<String> allPossibleForbiddenWords = allForbiddenWords.stream().filter(x -> !(x.contains(" ") || x.contains("-") || x.contains("."))).collect(Collectors.toList()); if (allForbiddenWords.size() > allPossibleForbiddenWords.size()) { logger.debug("Not using some forbidden words in query because characters forbidden by newznab are contained"); } if (!allPossibleForbiddenWords.isEmpty()) { StringBuilder queryBuilder = new StringBuilder(query); for (String word : allForbiddenWords) { if ((queryBuilder + " --" + word).length() < 255) { queryBuilder.append(" --").append(word); } } query = queryBuilder.toString(); } return query; }  }
NzbsOrg extends Newznab { protected String addForbiddenWords(SearchRequest searchRequest, String query) { List<String> allForbiddenWords = new ArrayList<>(searchRequest.getInternalData().getForbiddenWords()); allForbiddenWords.addAll(configProvider.getBaseConfig().getSearching().getForbiddenWords()); allForbiddenWords.addAll(searchRequest.getCategory().getForbiddenWords()); List<String> allPossibleForbiddenWords = allForbiddenWords.stream().filter(x -> !(x.contains(" ") || x.contains("-") || x.contains("."))).collect(Collectors.toList()); if (allForbiddenWords.size() > allPossibleForbiddenWords.size()) { logger.debug("Not using some forbidden words in query because characters forbidden by newznab are contained"); } if (!allPossibleForbiddenWords.isEmpty()) { StringBuilder queryBuilder = new StringBuilder(query); for (String word : allForbiddenWords) { if ((queryBuilder + " --" + word).length() < 255) { queryBuilder.append(" --").append(word); } } query = queryBuilder.toString(); } return query; }   }
NzbsOrg extends Newznab { protected String addForbiddenWords(SearchRequest searchRequest, String query) { List<String> allForbiddenWords = new ArrayList<>(searchRequest.getInternalData().getForbiddenWords()); allForbiddenWords.addAll(configProvider.getBaseConfig().getSearching().getForbiddenWords()); allForbiddenWords.addAll(searchRequest.getCategory().getForbiddenWords()); List<String> allPossibleForbiddenWords = allForbiddenWords.stream().filter(x -> !(x.contains(" ") || x.contains("-") || x.contains("."))).collect(Collectors.toList()); if (allForbiddenWords.size() > allPossibleForbiddenWords.size()) { logger.debug("Not using some forbidden words in query because characters forbidden by newznab are contained"); } if (!allPossibleForbiddenWords.isEmpty()) { StringBuilder queryBuilder = new StringBuilder(query); for (String word : allForbiddenWords) { if ((queryBuilder + " --" + word).length() < 255) { queryBuilder.append(" --").append(word); } } query = queryBuilder.toString(); } return query; }    }