List of usage examples for org.apache.solr.common.params FacetParams FACET_QUERY
String FACET_QUERY
To view the source code for org.apache.solr.common.params FacetParams FACET_QUERY.
Click Source Link
From source file:fi.nationallibrary.ndl.solr.request.RangeFieldFacets.java
License:Apache License
void parseParams(String type, String param) throws ParseException, IOException { localParams = QueryParsing.getLocalParams(param, req.getParams()); base = docs;//from w w w . j av a 2 s. c o m facetValue = param; key = param; if (localParams == null) return; // remove local params unless it's a query if (type != FacetParams.FACET_QUERY) { facetValue = localParams.get(CommonParams.VALUE); } // reset set the default key now that localParams have been removed key = facetValue; // allow explicit set of the key key = localParams.get(CommonParams.OUTPUT_KEY, key); // figure out if we need a new base DocSet String excludeStr = localParams.get(CommonParams.EXCLUDE); if (excludeStr == null) return; Map tagMap = (Map) req.getContext().get("tags"); if (tagMap != null && rb != null) { List<String> excludeTagList = StrUtils.splitSmart(excludeStr, ','); IdentityHashMap<Query, Boolean> excludeSet = new IdentityHashMap<Query, Boolean>(); for (String excludeTag : excludeTagList) { Object olst = tagMap.get(excludeTag); // tagMap has entries of List<String,List<QParser>>, but subject to change in the future if (!(olst instanceof Collection)) continue; for (Object o : (Collection) olst) { if (!(o instanceof QParser)) continue; QParser qp = (QParser) o; excludeSet.put(qp.getQuery(), Boolean.TRUE); } } if (excludeSet.size() == 0) return; List<Query> qlist = new ArrayList<Query>(); // add the base query if (!excludeSet.containsKey(rb.getQuery())) { qlist.add(rb.getQuery()); } // add the filters if (rb.getFilters() != null) { for (Query q : rb.getFilters()) { if (!excludeSet.containsKey(q)) { qlist.add(q); } } } // get the new base docset for this facet base = searcher.getDocSet(qlist); } }
From source file:org.apache.jackrabbit.core.query.lucene.FacetHandler.java
License:Open Source License
private void extractFacetParameters(String facetFunctionPrefix, NamedList<Object> parameters, int counter, Map.Entry<String, PropertyValue> column) throws RepositoryException { // first extract options from rep:facet() from column key final String key = column.getKey(); final String facetOptions = key.substring(key.indexOf(facetFunctionPrefix) + facetFunctionPrefix.length(), key.lastIndexOf(")")); // remember nodetype and query values if encountered so that we can process them once the whole facet is parsed String nodeType = null;//from www . jav a 2 s.com List<String> unparsedQueries = null; // loop invariants final String columnPropertyName = column.getValue().getPropertyName(); final String propertyName = columnPropertyName + SimpleJahiaJcrFacets.PROPNAME_INDEX_SEPARATOR + counter; // we can assert the facet type by checking whether the the options String contains date or range, otherwise, the type is field final boolean isQuery = facetOptions.contains(FacetParams.FACET_QUERY); String facetType = FacetParams.FACET_FIELD; // default facet type if (isQuery) { facetType = FacetParams.FACET_QUERY; } else if (facetOptions.contains("date")) { facetType = FacetParams.FACET_DATE; } else if (facetOptions.contains("range")) { facetType = FacetParams.FACET_RANGE; } parameters.add(facetType, propertyName); // populate parameters // each parameter name/value pair is separated from the next one by & so split on this final String[] paramPairs = StringUtils.split(facetOptions, "&"); for (String paramPair : paramPairs) { // for each pair, extract the name and value separated by = int separator = paramPair.indexOf('='); if (separator >= 0) { // todo: what should we do if a pair doesn't have an equal sign in it? final String paramName = paramPair.substring(0, separator); final String paramValue = paramPair.substring(separator + 1); // some parameters need to be specially processed and not be added as others so process them and exit current iteration when encountered if (paramName.equals("nodetype")) { nodeType = paramValue; // remember node type value for later processing continue; } else if (paramName.contains("query")) { if (unparsedQueries == null) { unparsedQueries = new LinkedList<String>(); } unparsedQueries.add(paramValue); // remember query value for later processing continue; } // create full parameter name and add its value to the parameters String facetOption = getFacetOption(paramName); parameters.add(getFullParameterName(propertyName, facetOption), paramValue); } } // node type parameter if (StringUtils.isEmpty(nodeType)) { // if we didn't have a node type specified in the given options, extract it from the selector name and create the associated parameter nodeType = getNodeTypeFromSelector(column.getValue().getSelectorName(), columnPropertyName); } // only add node type parameter if we're not dealing with a query if (!isQuery) { parameters.add(getFullParameterName(propertyName, getFacetOption("nodetype")), nodeType); } // deal with embedded query if needed, at this point, nodeType will have been either extracted or asserted from selector name if (unparsedQueries != null) { ExtendedPropertyDefinition epd = NodeTypeRegistry.getInstance().getNodeType(nodeType) .getPropertyDefinition(columnPropertyName); for (String unparsedQuery : unparsedQueries) { if (unparsedQuery.split("(?<!\\\\):").length == 1 && !columnPropertyName.equals("rep:facet()")) { if (epd != null) { String fieldNameInIndex = getFieldNameInIndex(propertyName, epd, ""); unparsedQuery = QueryParser.escape(fieldNameInIndex) + ":" + unparsedQuery; } } parameters.add(getFullParameterName(propertyName, "query"), unparsedQuery); } } }
From source file:org.jahia.services.search.facets.SimpleJahiaJcrFacets.java
License:Open Source License
@SuppressWarnings("unused") void parseParams(String type, String param) throws ParseException, IOException { // TODO: Should we activate that and how ? - we have no request object in backend // localParams = QueryParsing.getLocalParams(param, req.getParams()); localParams = QueryParsing.getLocalParams(param, params); base = docs;/*from w ww. j ava 2 s . com*/ facetValue = param; key = param; if (localParams == null) return; // remove local params unless it's a query if (!FacetParams.FACET_QUERY.equals(type)) { facetValue = localParams.get(CommonParams.VALUE); } // reset set the default key now that localParams have been removed key = facetValue; // allow explicit set of the key key = localParams.get(CommonParams.OUTPUT_KEY, key); // figure out if we need a new base DocSet String excludeStr = localParams.get(CommonParams.EXCLUDE); if (excludeStr == null) return; // TODO: Should we activate that and how ? - we have no request object in backend // Map tagMap = (Map)req.getContext().get("tags"); /*if (tagMap != null && rb != null) { List<String> excludeTagList = StrUtils.splitSmart(excludeStr,','); IdentityHashMap<Query,Boolean> excludeSet = new IdentityHashMap<Query,Boolean>(); for (String excludeTag : excludeTagList) { Object olst = tagMap.get(excludeTag); // tagMap has entries of List<String,List<QParser>>, but subject to change in the future if (!(olst instanceof Collection)) continue; for (Object o : (Collection<?>)olst) { if (!(o instanceof QParser)) continue; QParser qp = (QParser)o; excludeSet.put(qp.getQuery(), Boolean.TRUE); } } if (excludeSet.size() == 0) return; List<Query> qlist = new ArrayList<Query>(); // add the base query if (!excludeSet.containsKey(rb.getQuery())) { qlist.add(rb.getQuery()); } // add the filters if (rb.getFilters() != null) { for (Query q : rb.getFilters()) { if (!excludeSet.containsKey(q)) { qlist.add(q); } } } // get the new base docset for this facet base = getDocIdSet(qlist, ""); }*/ }
From source file:org.jahia.services.search.facets.SimpleJahiaJcrFacets.java
License:Open Source License
/** * Returns a list of facet counts for each of the facet queries specified in the params * //ww w . ja va2 s . c o m * @see FacetParams#FACET_QUERY */ public NamedList<Object> getFacetQueryCounts() throws IOException, ParseException { NamedList<Object> res = new SimpleOrderedMap<Object>(); /* Ignore CommonParams.DF - could have init param facet.query assuming * the schema default with query param DF intented to only affect Q. * If user doesn't want schema default for facet.query, they should be * explicit. */ // SolrQueryParser qp = searcher.getSchema().getSolrQueryParser(null); String[] facetQs = params.getParams(FacetParams.FACET_QUERY); if (null != facetQs && 0 != facetQs.length) { for (String q : facetQs) { try { Integer minCount = params.getFieldInt(q, FacetParams.FACET_MINCOUNT); if (minCount == null) { Boolean zeros = params.getFieldBool(q, FacetParams.FACET_ZEROS); // mincount = (zeros!=null && zeros) ? 0 : 1; minCount = (zeros != null && !zeros) ? 1 : 0; // current default is to include zeros. } for (String query : params.getFieldParams(q, "query")) { parseParams(FacetParams.FACET_QUERY, query); QueryParser qp = new JahiaQueryParser(FieldNames.FULLTEXT, new KeywordAnalyzer()); qp.setLowercaseExpandedTerms(false); Query qobj = qp.parse(query); long count = OpenBitSet.intersectionCount(getDocIdSet(qobj, ""), base); if (count >= minCount) { res.add(key, count); } } } catch (Exception e) { String msg = "Exception during facet.query of " + q; logger.warn(msg, e); addException(msg, e); } } } return res; }