/* (non-Javadoc)
@see org.archive.wayback.resourceindex.SearchResultFilter#filterSearchResult(org.archive.wayback.core.SearchResult)
162062
public int filterObject(CaptureSearchResult r) {
		int filterResult = ObjectFilter.FILTER_EXCLUDE; 
		
		try {
			PerfStats.timeStart(PerfStat.RobotsTotal);
			
			if(!notifiedSeen) {
				if(filterGroup != null) {
					filterGroup.setSawRobots();
				}
				notifiedSeen = true;
			}
			String resultURL = r.getOriginalUrl();
			String path = UrlOperations.getURLPath(resultURL);
			
			if (path.equals(ROBOT_SUFFIX) || r.isRobotIgnore()) {
				if(!notifiedPassed) {
					if(filterGroup != null) {
						filterGroup.setPassedRobots();
					}
					notifiedPassed = true;
				}
				return ObjectFilter.FILTER_INCLUDE;
			}
			
			if (pathsCache == null) {
				pathsCache = new HashMap<String,Integer>();
			} else {
				Integer result = pathsCache.get(r.getUrlKey());
				if (result != null) {
					return result;
				}
			}
			
			RobotRules rules = getRules(r);
			
			if(rules == null) {
				if((filterGroup == null) || (filterGroup.getRobotTimedOut() || filterGroup.getLiveWebGone())) {
					filterResult = ObjectFilter.FILTER_ABORT;
				}
			} else {
				if(!rules.blocksPathForUA(path, userAgent)) {
					if(!notifiedPassed) {
						if(filterGroup != null) {
							filterGroup.setPassedRobots();
						}
						notifiedPassed = true;
					}
					filterResult = ObjectFilter.FILTER_INCLUDE;
					LOGGER.finer("ROBOT: ALLOWED("+resultURL+")");
				} else {
					LOGGER.fine("ROBOT: BLOCKED("+resultURL+")");
				}
			}
			pathsCache.put(r.getUrlKey(), filterResult);
		} finally {
			PerfStats.timeEnd(PerfStat.RobotsTotal, false);
		}
		
		return filterResult;
	}
1152578
public void filterTable(String search) {

        m_container.removeAllContainerFilters();
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(search)) {
            if (CmsStringUtil.isEmptyOrWhitespaceOnly(m_dialog.getFurtherColumnId())) {
                m_container.addContainerFilter(new Or(new SimpleStringFilter(PROP_NAME, search, true, false)));
            } else {
                m_container.addContainerFilter(
                    new Or(
                        new SimpleStringFilter(PROP_NAME, search, true, false),
                        new SimpleStringFilter(m_dialog.getFurtherColumnId(), search, true, false)));
            }

        }
        if ((getValue() != null) & !((Set<String>)getValue()).isEmpty()) {
            setCurrentPageFirstItemId(((Set<String>)getValue()).iterator().next());
        }
    }
742273
@Override
    public List<PhoneNumber> searchForNumbers(String country, PhoneNumberSearchFilters listFilters) {
        if(logger.isDebugEnabled()) {
            logger.debug("searchPattern " + listFilters.getFilterPattern());
        }
        Pattern filterPattern = listFilters.getFilterPattern();
        String filterPatternString = null;
        if(filterPattern != null) {
            filterPatternString = filterPattern.toString().replaceAll("[^\\d]", "");
        }
        if(logger.isDebugEnabled()) {
            logger.debug("searchPattern simplified for nexmo " + filterPatternString);
        }

        String queryUri = searchURI + country;
        boolean queryParamAdded = false;
        if(("US".equalsIgnoreCase(country) || "CA".equalsIgnoreCase(country)) && listFilters.getAreaCode() != null) {
            // https://github.com/Mobicents/RestComm/issues/551 fixing the search pattern for US when Area Code is selected
            // https://github.com/Mobicents/RestComm/issues/602 fixing the search pattern for CA when Area Code is selected
            queryUri = queryUri + "?pattern=1" + listFilters.getAreaCode() + "&search_pattern=0";
            queryParamAdded = true;
        } else if(filterPatternString != null) {
            queryUri = queryUri + "?pattern=" + filterPatternString + "&search_pattern=1";
            queryParamAdded = true;
        }
        if(listFilters.getSmsEnabled() != null || listFilters.getVoiceEnabled() != null) {
            if(!queryParamAdded) {
                queryUri = queryUri + "?";
                queryParamAdded = true;
            } else {
                queryUri = queryUri + "&";
            }
            if(listFilters.getSmsEnabled() != null && listFilters.getVoiceEnabled() != null) {
                queryUri = queryUri + "features=SMS,VOICE";
            } else if(listFilters.getSmsEnabled() != null) {
                queryUri = queryUri + "features=SMS";
            } else {
                queryUri = queryUri + "features=VOICE";
            }
        }
        if(listFilters.getRangeIndex() != -1) {
            if(!queryParamAdded) {
                queryUri = queryUri + "?";
                queryParamAdded = true;
            } else {
                queryUri = queryUri + "&";
            }
            queryUri = queryUri + "index=" + listFilters.getRangeIndex();
        }
        if(listFilters.getRangeSize() != -1) {
            if(!queryParamAdded) {
                queryUri = queryUri + "?";
                queryParamAdded = true;
            } else {
                queryUri = queryUri + "&";
            }
            queryUri = queryUri + "size=" + listFilters.getRangeSize();
        }
        final HttpGet get = new HttpGet(queryUri);
        try {

            final DefaultHttpClient client = new DefaultHttpClient();
//                if (telestaxProxyEnabled) {
//                    // This will work as a flag for LB that this request will need to be modified and proxied to VI
//                    get.addHeader("TelestaxProxy", String.valueOf(telestaxProxyEnabled));
//                    // This will tell LB that this request is a getAvailablePhoneNumberByAreaCode request
//                    get.addHeader("RequestType", "GetAvailablePhoneNumbersByAreaCode");
//                    //This will let LB match the DID to a node based on the node host+port
//                    for (SipURI uri: containerConfiguration.getOutboundInterfaces()) {
//                        get.addHeader("OutboundIntf", uri.getHost()+":"+uri.getPort()+":"+uri.getTransportParam());
//                    }
//                }
            if(logger.isDebugEnabled()) {
                logger.debug("Nexmo query " + queryUri);
            }
            final HttpResponse response = client.execute(get);
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                final String content = StringUtils.toString(response.getEntity().getContent());
                JsonParser parser = new JsonParser();
                JsonObject jsonResponse = parser.parse(content).getAsJsonObject();
                if(logger.isDebugEnabled()) {
                    logger.debug("Nexmo response " + jsonResponse.toString());
                }
                JsonPrimitive countPrimitive = jsonResponse.getAsJsonPrimitive("count");
                if(countPrimitive == null) {
                    if(logger.isDebugEnabled()) {
                        logger.debug("No numbers found");
                    }
                    return new ArrayList<PhoneNumber>();
                }
                long count = countPrimitive.getAsLong();
                if(logger.isDebugEnabled()) {
                    logger.debug("Number of numbers found : "+count);
                }
                JsonArray nexmoNumbers = jsonResponse.getAsJsonArray("numbers");
                final List<PhoneNumber> numbers = toAvailablePhoneNumbers(nexmoNumbers, listFilters);
                return numbers;
            } else {
                logger.warn("Couldn't reach uri for getting Phone Numbers. Response status was: "+response.getStatusLine().getStatusCode());
            }
        } catch (final Exception e) {
            logger.warn("Couldn't reach uri for getting Phone Numbers" + uri, e);
        }

        return new ArrayList<PhoneNumber>();
    }
686505
@Override
	public List<ScopDescription> filterByDescription(String query) throws ScopIOException {
		try {
			ensureDesInstalled();
		} catch (IOException e) {
			throw new ScopIOException(e);
		}

		query = query.toLowerCase();
		List<ScopDescription> matches = new ArrayList<ScopDescription>();
		for (Integer i : sunidMap.keySet()){
			ScopDescription sc = sunidMap.get(i);

			if( sc.getDescription().toLowerCase().startsWith(query)){
				matches.add(sc);
			}
		}

		return matches;
	}
329254
@SuppressWarnings("unchecked")
    public void filterTable(String search) {

        m_container.removeAllContainerFilters();
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(search)) {
            m_container.addContainerFilter(
                new Or(
                    new SimpleStringFilter(TableColumn.Channel, search, true, false),
                    new SimpleStringFilter(TableColumn.ParentChannel, search, true, false),
                    new SimpleStringFilter(TableColumn.File, search, true, false)));
        }
        if ((getValue() != null) & !((Set<Logger>)getValue()).isEmpty()) {
            setCurrentPageFirstItemId(((Set<Logger>)getValue()).iterator().next());
        }
    }
1247604
@Override
    public PagedSearchResult uploadSearch(UploadSearchParams uploadSearchParams) {
        PagedSearchResult result = searchOperations.uploadSearch(uploadSearchParams);
        if(result!=null && enableAutoSolutionActionTrack) {
            String reqId = result.getReqId();
            this.sendSolutionActions("uploadsearch", reqId);
        }
        return result;
    }
763960
public int filterObject(CaptureSearchResult r) {
		String mime = r.getMimeType().toLowerCase();
		return validMimes.containsKey(mime) == includeIfContains ? 
				FILTER_INCLUDE : FILTER_EXCLUDE;
	}
1335655
private SearchFilter getSearchFilter(HttpServletRequest httpServletRequest) {
        SearchFilter ret = new SearchFilter();
        Set<String> keySet = httpServletRequest.getParameterMap().keySet();
        for (String key : keySet) {
            ret.setParam(String.valueOf(key), String.valueOf(httpServletRequest.getParameter(key)));
        }

        return ret;
    }
650631
public SearchResponse searchAll(String index, String type,
            QueryBuilder filterQueryBuilder) {
        return searchAll(index, type, filterQueryBuilder, null);
    }
927099
public static <T> void addAll(Collection<T> pagingResults, Collection<T> paging, BooleanExpression<T> filter)
	{
		if (pagingResults == null || paging == null)
			return;

		if (filter != null)
		{
			for (T obj : paging)
			{
				if (filter.apply(obj))
					pagingResults.add(obj);
			}
		}
		else
		{
			// add independent of a filter
			for (T obj : paging)
			{
				pagingResults.add(obj);
			}
		}
	}
399109
public List<Row> search(ExtendedFilter filter)
    {
        SecondaryIndexSearcher mostSelective = getHighestSelectivityIndexSearcher(filter.getClause());
        if (mostSelective == null)
            return Collections.emptyList();
        else
            return mostSelective.search(filter);
    }
106370
public void filter(Map<String, String> output, String key, String value,
			ResultURIConverter uriConverter, CaptureSearchResult result) {

		String keyUp = key.toUpperCase();

		// first stick it in as-is, or with prefix, then maybe we'll overwrite
		// with the later logic.
		if (dropHeaders.contains(keyUp))
			preserve(output, key, value);
		else
			preserveAlways(output, key, value);

		// rewrite Location header URLs
		if(rewriteHeaders.contains(keyUp)) {
			String baseUrl = result.getOriginalUrl();
			String cd = result.getCaptureTimestamp();
			// by the spec, these should be absolute already, but just in case:
			String u = UrlOperations.resolveUrl(baseUrl, value);
			output.put(key, uriConverter.makeReplayURI(cd,u));
		} else if(passThroughHeaders.contains(keyUp)) {
			// let's leave this one as-is:
			output.put(key,value);
		}
	}
312939
public int filterObject(CaptureSearchResult o) {
		if(client != null) {
			String url = o.getOriginalUrl();
			Date capDate = o.getCaptureDate();
			try {
				Rule r = client.getRule(url, capDate, new Date(), who);
				if(r != null) {
					String publicComment = r.getPublicComment();
					o.putCustom("ANOTATION", publicComment);
				}
			} catch (RuleOracleUnavailableException e) {
				e.printStackTrace();
				// should not happen: we forcibly disable robots retrievals 
			}
		}
		return FILTER_INCLUDE;
	}
1350270
@Override
	public int filterObject(CaptureSearchResult r) {
		if(!notifiedSeen) { 
			if(filterGroup != null) {
				filterGroup.setSawAdministrative();
			}
			notifiedSeen = true;
		}
		String surt;
		try {
			String url = canonicalizer.urlStringToKey(r.getOriginalUrl());
			surt = SURT.fromPlain(url);
//			surt = SURTTokenizer.prefixKey(url);
		} catch (URIException e) {
			
			//e.printStackTrace();
			return FILTER_EXCLUDE;
		}
		if(lastChecked != null) {
			if(lastChecked.equals(surt)) {
				if(lastCheckedExcluded) { 
					return ObjectFilter.FILTER_EXCLUDE;
				} else {
					// don't need to: already did last time...
					//filterGroup.setPassedAdministrative();
					return ObjectFilter.FILTER_INCLUDE;
				}
			}
		}
		lastChecked = surt;
		lastCheckedExcluded = isExcluded(surt);
		if(lastCheckedExcluded) {
			return ObjectFilter.FILTER_EXCLUDE;
		} else {
			if(!notifiedPassed) {
				if(filterGroup != null) {
					filterGroup.setPassedAdministrative();
				}
				notifiedPassed = true;
			}
			return ObjectFilter.FILTER_INCLUDE;
		}
			
	}
457911
private IQueryResult<T> filteredResult(IQueryResult<T> unfilteredResult) {
        List<T> unfilteredList = unfilteredResult.getResults();
        List<T> filteredList = unfilteredList == null ? null : filters.filter(unfilteredList);
        Map<String, Object> metadata = Collections.<String, Object> singletonMap("unfiltered", unfilteredResult);
        return QueryUtil.packageResult(filteredList, unfilteredResult.getStatus(), metadata);
    }
1360203
public SearchResults query(WaybackRequest wbRequest)
		throws ResourceIndexNotAvailableException,
		ResourceNotInArchiveException, BadQueryException,
		AccessControlException {
//		throw new ResourceIndexNotAvailableException("oops");
		ClosestTrackingCaptureFilterGroup closestGroup = new ClosestTrackingCaptureFilterGroup(wbRequest, canonicalizer);
		SearchResults results = urlToSearchResults(getRequestUrl(wbRequest),
				getSearchResultFilters(wbRequest, closestGroup));
        closestGroup.annotateResults(results);
        return results;
	}
1271983
public int filterObject(CaptureSearchResult r) {
		String captureDate = r.getCaptureTimestamp();
		
		int captureDateLength = Math.min(captureDate.length(), endDate.length());

		return (endDate.substring(0, captureDateLength).compareTo(
				captureDate) < 0) ? 
				FILTER_ABORT : FILTER_INCLUDE; 
	}