Search in sources :

Example 6 with MCRCondition

use of org.mycore.parsers.bool.MCRCondition in project mycore by MyCoRe-Org.

the class MCRConditionTransformer method groupConditionsByIndex.

/**
 * Build a table from index ID to a List of conditions referencing this
 * index
 */
@SuppressWarnings("rawtypes")
public static HashMap<String, List<MCRCondition>> groupConditionsByIndex(MCRSetCondition cond) {
    HashMap<String, List<MCRCondition>> table = new HashMap<>();
    @SuppressWarnings("unchecked") List<MCRCondition> children = cond.getChildren();
    for (MCRCondition child : children) {
        String index = getIndex(child);
        table.computeIfAbsent(index, k -> new ArrayList<>()).add(child);
    }
    return table;
}
Also used : MCRCondition(org.mycore.parsers.bool.MCRCondition) Iterator(java.util.Iterator) MCRAndCondition(org.mycore.parsers.bool.MCRAndCondition) Set(java.util.Set) HashMap(java.util.HashMap) MCRConfiguration(org.mycore.common.config.MCRConfiguration) Collectors(java.util.stream.Collectors) MCRException(org.mycore.common.MCRException) MCRQueryCondition(org.mycore.services.fieldquery.MCRQueryCondition) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) MCRSetCondition(org.mycore.parsers.bool.MCRSetCondition) Logger(org.apache.logging.log4j.Logger) MCRSortBy(org.mycore.services.fieldquery.MCRSortBy) MCRSolrConstants(org.mycore.solr.MCRSolrConstants) Map(java.util.Map) SolrQuery(org.apache.solr.client.solrj.SolrQuery) MCRSolrUtils(org.mycore.solr.MCRSolrUtils) ORDER(org.apache.solr.client.solrj.SolrQuery.ORDER) LogManager(org.apache.logging.log4j.LogManager) MCROrCondition(org.mycore.parsers.bool.MCROrCondition) SortClause(org.apache.solr.client.solrj.SolrQuery.SortClause) MCRNotCondition(org.mycore.parsers.bool.MCRNotCondition) MCRCondition(org.mycore.parsers.bool.MCRCondition) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with MCRCondition

use of org.mycore.parsers.bool.MCRCondition in project mycore by MyCoRe-Org.

the class MCRQLSearchUtils method getSolrQuery.

@SuppressWarnings("rawtypes")
public static SolrQuery getSolrQuery(MCRQuery query, Document input, HttpServletRequest request) {
    int rows = Integer.parseInt(input.getRootElement().getAttributeValue("numPerPage", "10"));
    List<String> returnFields = query.getReturnFields();
    MCRCondition condition = query.getCondition();
    HashMap<String, List<MCRCondition>> table;
    if (condition instanceof MCRSetCondition) {
        table = MCRConditionTransformer.groupConditionsByIndex((MCRSetCondition) condition);
    } else {
        // if there is only one condition its no set condition. we don't need to group
        LOGGER.warn("Condition is not SetCondition.");
        table = new HashMap<>();
        ArrayList<MCRCondition> conditionList = new ArrayList<>();
        conditionList.add(condition);
        table.put("metadata", conditionList);
    }
    boolean booleanAnd = !(condition instanceof MCROrCondition<?>);
    SolrQuery mergedSolrQuery = MCRConditionTransformer.buildMergedSolrQuery(query.getSortBy(), false, booleanAnd, table, rows, returnFields);
    String mask = input.getRootElement().getAttributeValue("mask");
    if (mask != null) {
        mergedSolrQuery.setParam("mask", mask);
        mergedSolrQuery.setParam("_session", request.getParameter("_session"));
    }
    return mergedSolrQuery;
}
Also used : ArrayList(java.util.ArrayList) MCRSetCondition(org.mycore.parsers.bool.MCRSetCondition) SolrQuery(org.apache.solr.client.solrj.SolrQuery) MCRCondition(org.mycore.parsers.bool.MCRCondition) MCROrCondition(org.mycore.parsers.bool.MCROrCondition) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

MCRCondition (org.mycore.parsers.bool.MCRCondition)7 ArrayList (java.util.ArrayList)5 List (java.util.List)5 SolrQuery (org.apache.solr.client.solrj.SolrQuery)4 MCROrCondition (org.mycore.parsers.bool.MCROrCondition)4 MCRSetCondition (org.mycore.parsers.bool.MCRSetCondition)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 MCRAndCondition (org.mycore.parsers.bool.MCRAndCondition)3 MCRNotCondition (org.mycore.parsers.bool.MCRNotCondition)3 MCRQueryCondition (org.mycore.services.fieldquery.MCRQueryCondition)3 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 ORDER (org.apache.solr.client.solrj.SolrQuery.ORDER)2 SortClause (org.apache.solr.client.solrj.SolrQuery.SortClause)2 MCRException (org.mycore.common.MCRException)2