use of org.codice.ddf.opensearch.query.OpenSearchQuery in project ddf by codice.
the class OpenSearchEndpoint method processQuery.
/**
* @param searchTerms Space delimited list of search terms.
* @param maxResults Maximum # of results to return. If count is also specified, the count value will
* take precedence over the maxResults value
* @param sources Comma delimited list of data sources to query (default: default sources selected).
* @param maxTimeout Maximum timeout (msec) for query to respond (default: mt=30000).
* @param startIndex Index of first result to return. Integer >= 0 (default: start=1).
* @param count Number of results to retrieve per page (default: count=10).
* @param geometry WKT Geometries (Support POINT and POLYGON).
* @param bbox Comma delimited list of lat/lon (deg) bounding box coordinates (geo format:
* geo:bbox ~ West,South,East,North).
* @param polygon Comma delimited list of lat/lon (deg) pairs, in clockwise order around the
* polygon, with the last point being the same as the first in order to close the
* polygon.
* @param lat Latitude in decimal degrees (typical GPS receiver WGS84 coordinates).
* @param lon Longitude in decimal degrees (typical GPS receiver WGS84 coordinates).
* @param radius The radius (m) parameter, used with the lat and lon parameters, specifies the
* search distance from this point (default: radius=5000).
* @param dateStart Specifies the beginning of the time slice of the search on the modified time field
* (RFC-3339 - Date and Time format, i.e. YYYY-MM-DDTHH:mm:ssZ). Default value of
* "1970-01-01T00:00:00Z" is used when dtend is indicated but dtstart is not
* specified
* @param dateEnd Specifies the ending of the time slice of the search on the modified time field
* (RFC-3339 - Date and Time format, i.e. YYYY-MM-DDTHH:mm:ssZ). Current GMT
* date/time is used when dtstart is specified but not dtend.
* @param dateOffset Specifies an offset, backwards from the current time, to search on the modified
* time field for entries. Defined in milliseconds.
* @param sort Specifies sort by field as sort=<sbfield>:<sborder>, where <sbfield> may be 'date'
* or 'relevance' (default is 'relevance'). The conditional param <sborder> is
* optional but has a value of 'asc' or 'desc' (default is 'desc'). When <sbfield> is
* 'relevance', <sborder> must be 'desc'.
* @param format Defines the format that the return type should be in. (example:atom, html)
* @param selector Defines a comma delimited list of XPath selectors to narrow the query.
* @param type Specifies the type of data to search for. (example: nitf)
* @param versions Specifies the versions in a comma delimited list.
* @return
*/
@GET
public Response processQuery(@QueryParam(PHRASE) String searchTerms, @QueryParam(MAX_RESULTS) String maxResults, @QueryParam(SOURCES) String sources, @QueryParam(MAX_TIMEOUT) String maxTimeout, @QueryParam(START_INDEX) String startIndex, @QueryParam(COUNT) String count, @QueryParam(GEOMETRY) String geometry, @QueryParam(BBOX) String bbox, @QueryParam(POLYGON) String polygon, @QueryParam(LAT) String lat, @QueryParam(LON) String lon, @QueryParam(RADIUS) String radius, @QueryParam(DATE_START) String dateStart, @QueryParam(DATE_END) String dateEnd, @QueryParam(DATE_OFFSET) String dateOffset, @QueryParam(SORT) String sort, @QueryParam(FORMAT) String format, @QueryParam(SELECTOR) String selector, @Context UriInfo ui, @QueryParam(TYPE) String type, @QueryParam(VERSION) String versions, @Context HttpServletRequest request) {
final String methodName = "processQuery";
LOGGER.trace("ENTERING: {}", methodName);
Response response;
String localCount = count;
LOGGER.debug("request url: {}", ui.getRequestUri());
// honor maxResults if count is not specified
if ((StringUtils.isEmpty(localCount)) && (!(StringUtils.isEmpty(maxResults)))) {
LOGGER.debug("setting count to: {}", maxResults);
localCount = maxResults;
}
try {
String queryFormat = format;
OpenSearchQuery query = createNewQuery(startIndex, localCount, sort, maxTimeout);
if (!(StringUtils.isEmpty(sources))) {
LOGGER.debug("Received site names from client.");
Set<String> siteSet = new HashSet<String>(Arrays.asList(StringUtils.stripAll(sources.split(","))));
// eventually remove support for it.
if (siteSet.remove(LOCAL)) {
LOGGER.debug("Found 'local' alias, replacing with {}.", SystemInfo.getSiteName());
siteSet.add(SystemInfo.getSiteName());
}
if (siteSet.contains(framework.getId()) && siteSet.size() == 1) {
LOGGER.debug("Only local site specified, saving overhead and just performing a local query on " + framework.getId() + ".");
} else {
LOGGER.debug("Querying site set: {}", siteSet);
query.setSiteIds(siteSet);
}
query.setIsEnterprise(false);
} else {
LOGGER.debug("No sites found, defaulting to enterprise query.");
query.setIsEnterprise(true);
}
// contextual
if (searchTerms != null && !searchTerms.trim().isEmpty()) {
try {
query.addContextualFilter(searchTerms, selector);
} catch (ParsingException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
// single temporal criterion per query
if ((dateStart != null && !dateStart.trim().isEmpty()) || (dateEnd != null && !dateEnd.trim().isEmpty()) || (dateOffset != null && !dateOffset.trim().isEmpty())) {
query.addTemporalFilter(dateStart, dateEnd, dateOffset);
}
// spatial
// single spatial criterion per query
addSpatialFilter(query, geometry, polygon, bbox, radius, lat, lon);
if (type != null && !type.trim().isEmpty()) {
query.addTypeFilter(type, versions);
}
Map<String, Serializable> properties = new HashMap<String, Serializable>();
for (Object key : request.getParameterMap().keySet()) {
if (key instanceof String) {
Object value = request.getParameterMap().get(key);
if (value instanceof Serializable) {
properties.put((String) key, ((String[]) value)[0]);
}
}
}
response = executeQuery(queryFormat, query, ui, properties);
} catch (IllegalArgumentException iae) {
LOGGER.info("Bad input found while executing a query", iae);
response = Response.status(Response.Status.BAD_REQUEST).entity(wrapStringInPreformattedTags(iae.getMessage())).build();
} catch (RuntimeException re) {
LOGGER.info("Exception while executing a query", re);
response = Response.serverError().entity(wrapStringInPreformattedTags("Exception while executing a query")).build();
}
LOGGER.trace("EXITING: {}", methodName);
return response;
}
Aggregations