use of annis.service.objects.OrderType in project ANNIS by korpling.
the class SolutionSqlGenerator method orderByClause.
@Override
public String orderByClause(QueryData queryData, List<QueryNode> alternative, String indent) {
OrderType order = OrderType.ascending;
List<LimitOffsetQueryData> ext = queryData.getExtensions(LimitOffsetQueryData.class);
if (!ext.isEmpty()) {
order = ext.get(0).getOrder();
}
if (order == OrderType.random) {
return "random()";
} else {
String appendix = "";
if (order == OrderType.descending) {
appendix = " DESC";
} else if (order == OrderType.ascending) {
appendix = " ASC";
}
List<Long> corpusList = queryData.getCorpusList();
List<String> ids = new ArrayList<>();
if (corpusList.size() > 1) {
// add the artificial "source index" which corresponds to the toplevel corpus name
ids.add("sourceIdx");
}
// add the node ID for each output node an the category ID
for (int i = 1; i <= queryData.getMaxWidth(); ++i) {
ids.add("id" + i + appendix);
if (annoCondition != null) {
ids.add("cat" + i + appendix);
}
}
return StringUtils.join(ids, ", ");
}
}
use of annis.service.objects.OrderType in project ANNIS by korpling.
the class SearchOptionsPanel method attach.
@Override
public void attach() {
super.attach();
contextContainerLeft.setItemSorter(new IntegerIDSorter());
contextContainerRight.setItemSorter(new IntegerIDSorter());
resultsPerPageContainer.setItemSorter(new IntegerIDSorter());
resultsPerPageContainer.removeAllItems();
for (Integer i : PREDEFINED_PAGE_SIZES) {
resultsPerPageContainer.addItem(i);
}
if (getUI() instanceof AnnisUI) {
AnnisUI ui = (AnnisUI) getUI();
state = ui.getQueryState();
Background.run(new CorpusConfigUpdater(ui, state.getSelectedCorpora().getValue(), false));
cbLeftContext.setNewItemHandler(new CustomContext(maxLeftContext, contextContainerLeft, state.getLeftContext()));
cbRightContext.setNewItemHandler(new CustomContext(maxRightContext, contextContainerRight, state.getRightContext()));
cbResultsPerPage.setNewItemHandler(new CustomResultSize(resultsPerPageContainer, state.getLimit()));
cbLeftContext.setPropertyDataSource(state.getLeftContext());
cbRightContext.setPropertyDataSource(state.getRightContext());
cbResultsPerPage.setPropertyDataSource(state.getLimit());
cbSegmentation.setPropertyDataSource(state.getContextSegmentation());
orderContainer.removeAllItems();
for (OrderType t : OrderType.values()) {
orderContainer.addItem(t);
}
cbOrder.setPropertyDataSource(state.getOrder());
}
}
use of annis.service.objects.OrderType in project ANNIS by korpling.
the class QueryServiceImpl method find.
@GET
@Path("search/find")
@Produces({ "application/xml", "text/plain" })
@Override
public Response find(@QueryParam("q") String query, @QueryParam("corpora") String rawCorpusNames, @DefaultValue("0") @QueryParam("offset") String offsetRaw, @DefaultValue("-1") @QueryParam("limit") String limitRaw, @DefaultValue("ascending") @QueryParam("order") String orderRaw) throws IOException {
requiredParameter(query, "q", "AnnisQL query");
requiredParameter(rawCorpusNames, "corpora", "comma separated list of corpus names");
Subject user = SecurityUtils.getSubject();
List<String> corpusNames = splitCorpusNamesFromRaw(rawCorpusNames);
for (String c : corpusNames) {
user.checkPermission("query:find:" + c);
}
int offset = Integer.parseInt(offsetRaw);
int limit = Integer.parseInt(limitRaw);
OrderType order;
try {
order = OrderType.valueOf(orderRaw.toLowerCase());
} catch (IllegalArgumentException ex) {
throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).type(MediaType.TEXT_PLAIN).entity("parameter 'order' has the invalid value '" + orderRaw + "'. It should be one of" + " 'ascending', 'random' or 'descending").build());
}
final QueryData data = queryDataFromParameters(query, rawCorpusNames);
data.setCorpusConfiguration(queryDao.getCorpusConfiguration());
data.addExtension(new LimitOffsetQueryData(offset, limit, order));
String acceptHeader = request.getHeader(HttpHeaders.ACCEPT);
if (acceptHeader == null || acceptHeader.trim().isEmpty()) {
acceptHeader = "*/*";
}
List<String> knownTypes = Lists.newArrayList("text/plain", "application/xml");
// find the best matching mime type
String bestMediaTypeMatch = MIMEParse.bestMatch(knownTypes, acceptHeader);
if ("text/plain".equals(bestMediaTypeMatch)) {
return Response.ok(findRaw(data, rawCorpusNames, query), "text/plain").build();
} else {
List<Match> result = findXml(data, rawCorpusNames, query);
return Response.ok().type("application/xml").entity(new GenericEntity<MatchGroup>(new MatchGroup(result)) {
}).build();
}
}
Aggregations