// long maxQueryTime;
// long minimumNumberOfResults;
// List<Facet> facets;
// List<SortField> sortFields;
BlurQuery blurQuery = new BlurQuery();
blurQuery.setQuery(query);
Selector selector = new Selector(Main.selector);
if (!query.isRowQuery()) {
selector.setRecordOnly(true);
}
blurQuery.setSelector(selector);
blurQuery.setCacheResult(false);
blurQuery.setUseCacheIfPresent(false);
if (commandLine.hasOption(START)) {
String startStr = commandLine.getOptionValue(START);
blurQuery.setStart(Long.parseLong(startStr));
}
if (commandLine.hasOption(FETCH)) {
String fetchStr = commandLine.getOptionValue(FETCH);
blurQuery.setFetch(Integer.parseInt(fetchStr));
}
if (commandLine.hasOption(MAX_QUERY_TIME)) {
String maxQueryTimeStr = commandLine.getOptionValue(MAX_QUERY_TIME);
blurQuery.setMaxQueryTime(Long.parseLong(maxQueryTimeStr));
}
if (commandLine.hasOption(MINIMUM_NUMBER_OF_RESULTS)) {
String minNumbResultsStr = commandLine.getOptionValue(MINIMUM_NUMBER_OF_RESULTS);
blurQuery.setMinimumNumberOfResults(Long.parseLong(minNumbResultsStr));
}
if (commandLine.hasOption(ROW_ID)) {
String rowId = commandLine.getOptionValue(ROW_FILTER);
blurQuery.setRowId(rowId);
}
List<Facet> facets = new ArrayList<Facet>();
for (Option option : options) {
if (option.getOpt().equals(FACET)) {
List<String> valuesList = option.getValuesList();
Facet facet = new Facet();
facet.setQueryStr(join(valuesList, " "));
facets.add(facet);
}
}
if (!facets.isEmpty()) {
blurQuery.setFacets(facets);
}
List<SortField> sortFields = new ArrayList<SortField>();
for (Option option : options) {
if (option.getOpt().equals(SORT)) {
List<String> valuesList = option.getValuesList();
if (valuesList.size() == 2) {
sortFields.add(new SortField(valuesList.get(0), valuesList.get(1), false));
} else if (valuesList.size() == 3) {
sortFields.add(new SortField(valuesList.get(0), valuesList.get(1), Boolean.parseBoolean(valuesList.get(2))));
} else {
throw new RuntimeException("Sort take 2 or 3 parameters.");
}
}
}
if (!sortFields.isEmpty()) {
blurQuery.setSortFields(sortFields);
}
if (Main.highlight) {
blurQuery.getSelector().setHighlightOptions(new HighlightOptions());
}
return blurQuery;
}