Search in sources :

Example 1 with OrderType

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, ", ");
    }
}
Also used : OrderType(annis.service.objects.OrderType) ArrayList(java.util.ArrayList) LimitOffsetQueryData(annis.sqlgen.extensions.LimitOffsetQueryData)

Example 2 with OrderType

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());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OrderType(annis.service.objects.OrderType) AnnisUI(annis.gui.AnnisUI)

Example 3 with OrderType

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();
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) QueryData(annis.ql.parser.QueryData) LimitOffsetQueryData(annis.sqlgen.extensions.LimitOffsetQueryData) AnnotateQueryData(annis.sqlgen.extensions.AnnotateQueryData) MatrixQueryData(annis.sqlgen.MatrixQueryData) Subject(org.apache.shiro.subject.Subject) Match(annis.service.objects.Match) OrderType(annis.service.objects.OrderType) GenericEntity(javax.ws.rs.core.GenericEntity) MatchGroup(annis.service.objects.MatchGroup) LimitOffsetQueryData(annis.sqlgen.extensions.LimitOffsetQueryData) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

OrderType (annis.service.objects.OrderType)3 LimitOffsetQueryData (annis.sqlgen.extensions.LimitOffsetQueryData)2 AnnisUI (annis.gui.AnnisUI)1 QueryData (annis.ql.parser.QueryData)1 Match (annis.service.objects.Match)1 MatchGroup (annis.service.objects.MatchGroup)1 MatrixQueryData (annis.sqlgen.MatrixQueryData)1 AnnotateQueryData (annis.sqlgen.extensions.AnnotateQueryData)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 GenericEntity (javax.ws.rs.core.GenericEntity)1 Subject (org.apache.shiro.subject.Subject)1