public static java.lang.String | translateHttpSearchRequest(org.apache.lucene.gdata.search.config.IndexSchema schema, java.util.Map parameterMap, java.lang.String categoryQuery)This method does a little preprocessing of the query. Basically it will map the given request parameters to a lucene syntax. Each
parameter matching a index field in the given schema will be translated into a grouped query string according to the lucene query syntax.
- title=foo bar AND "FooBar" will be title:(foo bar AND "FooBar)
- updated-min=2005-08-09T10:57:00-08:00 will be translated to updated:[1123613820000 TO 9223372036854775807] according to the gdata protocol
// private static final String GDATA_CATEGORY_FIEL =
STANDARD_REQUEST_PARAMETER.add("max-results");
STANDARD_REQUEST_PARAMETER.add("start-index");
STANDARD_REQUEST_PARAMETER.add("alt");
Set<String> searchableFieldNames = schema.getSearchableFieldNames();
Set<String> parameterSet = parameterMap.keySet();
StringBuilder translatedQuery = new StringBuilder();
if(categoryQuery != null){
translatedQuery.append(translateCategory(translatedQuery,categoryQuery));
}
String updateMin = null;
String updateMax = null;
for (String parameterName : parameterSet) {
if (STANDARD_REQUEST_PARAMETER.contains(parameterName))
continue;
if (searchableFieldNames.contains(parameterName)) {
translatedQuery.append(parameterName).append(":(");
translatedQuery.append(parameterMap.get(parameterName)[0]);
translatedQuery.append(") ");
continue;
}
if(parameterName.equals(GDATA_DEFAULT_SEARCH_PARAMETER)){
translatedQuery.append(schema.getDefaultSearchField());
translatedQuery.append(":(");
translatedQuery.append(parameterMap.get(parameterName)[0]);
translatedQuery.append(") ");
continue;
}
if(parameterName.endsWith("updated-min")){
updateMin = parameterMap.get(parameterName)[0];
continue;
}
if(parameterName.endsWith("updated-max")){
updateMax = parameterMap.get(parameterName)[0];
continue;
}
throw new RuntimeException("Can not apply parameter -- invalid -- "
+ parameterName);
}
if(updateMax!=null || updateMin!= null)
translatedQuery.append(translateUpdate(updateMin,updateMax));
return translatedQuery.length() == 0?null:translatedQuery.toString();
|