org.apache.solr.common.params.GroupParams Java Examples
The following examples show how to use
org.apache.solr.common.params.GroupParams.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleFacets.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Returns a grouped facet count for the facet query * * @see FacetParams#FACET_QUERY */ public int getGroupedFacetQueryCount(Query facetQuery, DocSet docSet) throws IOException { // It is okay to retrieve group.field from global because it is never a local param String groupField = global.get(GroupParams.GROUP_FIELD); if (groupField == null) { throw new SolrException ( SolrException.ErrorCode.BAD_REQUEST, "Specify the group.field as parameter or local parameter" ); } @SuppressWarnings({"rawtypes"}) AllGroupsCollector collector = new AllGroupsCollector<>(new TermGroupSelector(groupField)); searcher.search(QueryUtils.combineQueryAndFilter(facetQuery, docSet.getTopFilter()), collector); return collector.getGroupCount(); }
Example #2
Source File: SimpleFacets.java From lucene-solr with Apache License 2.0 | 6 votes |
@SuppressWarnings({"rawtypes"}) public NamedList getHeatmapCounts() throws IOException, SyntaxError { final NamedList<Object> resOuter = new SimpleOrderedMap<>(); String[] unparsedFields = rb.req.getParams().getParams(FacetParams.FACET_HEATMAP); if (unparsedFields == null || unparsedFields.length == 0) { return resOuter; } if (global.getBool(GroupParams.GROUP_FACET, false)) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Heatmaps can't be used with " + GroupParams.GROUP_FACET); } for (String unparsedField : unparsedFields) { final ParsedParams parsed = parseParams(FacetParams.FACET_HEATMAP, unparsedField); // populates facetValue, rb, params, docs resOuter.add(parsed.key, SpatialHeatmapFacets.getHeatmapForField(parsed.key, parsed.facetValue, rb, parsed.params, parsed.docs)); } return resOuter; }
Example #3
Source File: AbstractReSearcherComponent.java From solr-researcher with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("rawtypes") public void init(NamedList args) { maxOriginalResults = getInt(args, "maxOriginalResults"); String tmp = (String) args.get("allComponentNames"); if (tmp != null) { componentNames.addAll(Arrays.asList(tmp.split("\\s*,\\s*"))); } componentNames.add(getComponentName()); componentNames.add(FacetComponent.COMPONENT_NAME); componentNames.add(HighlightComponent.COMPONENT_NAME); componentNames.add(StatsComponent.COMPONENT_NAME); componentNames.add(TermsComponent.COMPONENT_NAME); componentNames.add(TermVectorComponent.COMPONENT_NAME); componentNames.add(SpellCheckComponent.COMPONENT_NAME); componentNames.add(MoreLikeThisComponent.COMPONENT_NAME); componentNames.add(GroupParams.GROUP); componentNames.add("queryRelaxer"); componentNames.add("DymReSearcher"); componentNames.add("autoComplete"); commonMisspellingsFileLocation = (String) args.get("commonMisspellingsFile"); commonMisspellingsMap = CommonMisspellings.loadCommonMisspellingsFile(commonMisspellingsFileLocation); }
Example #4
Source File: SimpleFacets.java From lucene-solr with Apache License 2.0 | 5 votes |
public void getFacetQueryCount(ParsedParams parsed, NamedList<Integer> res) throws SyntaxError, IOException { // TODO: slight optimization would prevent double-parsing of any localParams // TODO: SOLR-7753 Query qobj = QParser.getParser(parsed.facetValue, req).getQuery(); if (qobj == null) { res.add(parsed.key, 0); } else if (parsed.params.getBool(GroupParams.GROUP_FACET, false)) { res.add(parsed.key, getGroupedFacetQueryCount(qobj, parsed.docs)); } else { res.add(parsed.key, searcher.numDocs(qobj, parsed.docs)); } }
Example #5
Source File: SimpleFacets.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Returns a <code>NamedList</code> with each entry having the "key" of the interval as name and the count of docs * in that interval as value. All intervals added in the request are included in the returned * <code>NamedList</code> (included those with 0 count), and it's required that the order of the intervals * is deterministic and equals in all shards of a distributed request, otherwise the collation of results * will fail. * */ public NamedList<Object> getFacetIntervalCounts() throws IOException, SyntaxError { NamedList<Object> res = new SimpleOrderedMap<Object>(); String[] fields = global.getParams(FacetParams.FACET_INTERVAL); if (fields == null || fields.length == 0) return res; for (String field : fields) { final ParsedParams parsed = parseParams(FacetParams.FACET_INTERVAL, field); String[] intervalStrs = parsed.required.getFieldParams(parsed.facetValue, FacetParams.FACET_INTERVAL_SET); SchemaField schemaField = searcher.getCore().getLatestSchema().getField(parsed.facetValue); if (parsed.params.getBool(GroupParams.GROUP_FACET, false)) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Interval Faceting can't be used with " + GroupParams.GROUP_FACET); } if (schemaField.getType().isPointField() && !schemaField.hasDocValues()) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Can't use interval faceting on a PointField without docValues"); } SimpleOrderedMap<Integer> fieldResults = new SimpleOrderedMap<Integer>(); res.add(parsed.key, fieldResults); IntervalFacets intervalFacets = new IntervalFacets(schemaField, searcher, parsed.docs, intervalStrs, parsed.params); for (FacetInterval interval : intervalFacets) { fieldResults.add(interval.getKey(), interval.getCount()); } } return res; }
Example #6
Source File: ExpandComponent.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void prepare(ResponseBuilder rb) throws IOException { if (rb.req.getParams().getBool(ExpandParams.EXPAND, false)) { if (rb.req.getParams().getBool(GroupParams.GROUP, false)) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Can not use expand with Grouping enabled"); } rb.doExpand = true; } }
Example #7
Source File: SpellCheckCollatorTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings({"unchecked", "rawtypes"}) public void testCollateWithGrouping() throws Exception { SolrCore core = h.getCore(); SearchComponent speller = core.getSearchComponent("spellcheck"); assertTrue("speller is null and it shouldn't be", speller != null); ModifiableSolrParams params = new ModifiableSolrParams(); params.add(SpellCheckComponent.COMPONENT_NAME, "true"); params.add(SpellingParams.SPELLCHECK_BUILD, "true"); params.add(SpellingParams.SPELLCHECK_COUNT, "10"); params.add(SpellingParams.SPELLCHECK_COLLATE, "true"); params.add(SpellingParams.SPELLCHECK_MAX_COLLATION_TRIES, "5"); params.add(SpellingParams.SPELLCHECK_MAX_COLLATIONS, "1"); params.add(CommonParams.Q, "lowerfilt:(+fauth)"); params.add(GroupParams.GROUP, "true"); params.add(GroupParams.GROUP_FIELD, "id"); //Because a FilterQuery is applied which removes doc id#1 from possible hits, we would //not want the collations to return us "lowerfilt:(+faith +hope +loaves)" as this only matches doc id#1. SolrRequestHandler handler = core.getRequestHandler("/spellCheckCompRH"); SolrQueryResponse rsp = new SolrQueryResponse(); rsp.addResponseHeader(new SimpleOrderedMap()); SolrQueryRequest req = new LocalSolrQueryRequest(core, params); handler.handleRequest(req, rsp); req.close(); NamedList values = rsp.getValues(); NamedList spellCheck = (NamedList) values.get("spellcheck"); NamedList collationHolder = (NamedList) spellCheck.get("collations"); List<String> collations = collationHolder.getAll("collation"); assertTrue(collations.size() == 1); }
Example #8
Source File: TestQueryRelaxerComponent.java From solr-researcher with Apache License 2.0 | 5 votes |
@Test public void testGroup2() { assertQ(req(CommonParams.QT, "dismax_relaxer", CommonParams.Q, "+_query_:\"{!type=edismax qf='foo^10.0' v='apple google' mm=100% relax=on}\" +_query_:\"{!type=edismax qf='foo^10.0' v='apple google' mm=0% relax=on}\"", QueryRelaxerComponent.COMPONENT_NAME, "true", GroupParams.GROUP, "true", GroupParams.GROUP_FIELD, "id", GroupParams.GROUP_LIMIT, "3", GroupParams.GROUP_TOTAL_COUNT, "true") ,"*[count(//result[@name='response'])=0]" ,"//arr[@name='relaxer_suggestions']/lst[1]//result[@numFound='1']" ); }
Example #9
Source File: TestQueryRelaxerComponent.java From solr-researcher with Apache License 2.0 | 5 votes |
@Test public void testGroup() { assertQ(req(CommonParams.QT, "dismax_relaxer", CommonParams.Q, "bi marley ", QueryRelaxerComponent.COMPONENT_NAME, "true", GroupParams.GROUP, "true", GroupParams.GROUP_FIELD, "id") ,"//arr[@name='relaxer_suggestions']/lst[1]/str[@name='relaxedQuery'][.='marley']" ,"//arr[@name='relaxer_suggestions']/lst[1]/lst[@name='relaxer_grouped']/lst[@name='id']/int[@name='matches'][.='7']" ); }
Example #10
Source File: TopGroupsShardRequestFactory.java From lucene-solr with Apache License 2.0 | 4 votes |
private ShardRequest[] createRequest(ResponseBuilder rb, String[] shards) { ShardRequest sreq = new ShardRequest(); sreq.shards = shards; sreq.purpose = ShardRequest.PURPOSE_GET_TOP_IDS; sreq.params = new ModifiableSolrParams(rb.req.getParams()); // If group.format=simple group.offset doesn't make sense Grouping.Format responseFormat = rb.getGroupingSpec().getResponseFormat(); if (responseFormat == Grouping.Format.simple || rb.getGroupingSpec().isMain()) { sreq.params.remove(GroupParams.GROUP_OFFSET); } sreq.params.remove(ShardParams.SHARDS); // set the start (offset) to 0 for each shard request so we can properly merge // results from the start. if (rb.shards_start > -1) { // if the client set shards.start set this explicitly sreq.params.set(CommonParams.START, rb.shards_start); } else { sreq.params.set(CommonParams.START, "0"); } if (rb.shards_rows > -1) { // if the client set shards.rows set this explicitly sreq.params.set(CommonParams.ROWS, rb.shards_rows); } else { sreq.params.set(CommonParams.ROWS, rb.getSortSpec().getOffset() + rb.getSortSpec().getCount()); } sreq.params.set(GroupParams.GROUP_DISTRIBUTED_SECOND, "true"); final IndexSchema schema = rb.req.getSearcher().getSchema(); for (Map.Entry<String, Collection<SearchGroup<BytesRef>>> entry : rb.mergedSearchGroups.entrySet()) { for (SearchGroup<BytesRef> searchGroup : entry.getValue()) { String groupValue; if (searchGroup.groupValue != null) { FieldType fieldType = schema.getField(entry.getKey()).getType(); groupValue = fieldType.indexedToReadable(searchGroup.groupValue, new CharsRefBuilder()).toString(); } else { groupValue = GROUP_NULL_VALUE; } sreq.params.add(GroupParams.GROUP_DISTRIBUTED_TOPGROUPS_PREFIX + entry.getKey(), groupValue); } } if ((rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES) != 0 || rb.getSortSpec().includesScore()) { sreq.params.set(CommonParams.FL, schema.getUniqueKeyField().getName() + ",score"); } else { sreq.params.set(CommonParams.FL, schema.getUniqueKeyField().getName()); } int origTimeAllowed = sreq.params.getInt(CommonParams.TIME_ALLOWED, -1); if (origTimeAllowed > 0) { sreq.params.set(CommonParams.TIME_ALLOWED, Math.max(1,origTimeAllowed - rb.firstPhaseElapsedTime)); } return new ShardRequest[] {sreq}; }
Example #11
Source File: StoredFieldsShardRequestFactory.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public ShardRequest[] constructRequest(ResponseBuilder rb) { HashMap<String, Set<ShardDoc>> shardMap = new HashMap<>(); for (TopGroups<BytesRef> topGroups : rb.mergedTopGroups.values()) { for (GroupDocs<BytesRef> group : topGroups.groups) { mapShardToDocs(shardMap, group.scoreDocs); } } for (QueryCommandResult queryCommandResult : rb.mergedQueryCommandResults.values()) { mapShardToDocs(shardMap, queryCommandResult.getTopDocs().scoreDocs); } ShardRequest[] shardRequests = new ShardRequest[shardMap.size()]; SchemaField uniqueField = rb.req.getSchema().getUniqueKeyField(); int i = 0; for (Collection<ShardDoc> shardDocs : shardMap.values()) { ShardRequest sreq = new ShardRequest(); sreq.purpose = ShardRequest.PURPOSE_GET_FIELDS; sreq.shards = new String[] {shardDocs.iterator().next().shard}; sreq.params = new ModifiableSolrParams(); sreq.params.add( rb.req.getParams()); sreq.params.remove(GroupParams.GROUP); sreq.params.remove(CommonParams.SORT); sreq.params.remove(ResponseBuilder.FIELD_SORT_VALUES); // we need to ensure the uniqueField is included for collating docs with their return fields if (! rb.rsp.getReturnFields().wantsField(uniqueField.getName())) { // the user didn't ask for it, so we have to... sreq.params.add(CommonParams.FL, uniqueField.getName()); } List<String> ids = new ArrayList<>(shardDocs.size()); for (ShardDoc shardDoc : shardDocs) { ids.add(shardDoc.id.toString()); } sreq.params.add(ShardParams.IDS, StrUtils.join(ids, ',')); shardRequests[i++] = sreq; } return shardRequests; }
Example #12
Source File: SearchGroupsRequestFactory.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public ShardRequest[] constructRequest(ResponseBuilder rb) { ShardRequest sreq = new ShardRequest(); GroupingSpecification groupingSpecification = rb.getGroupingSpec(); if (groupingSpecification.getFields().length == 0) { return new ShardRequest[0]; } sreq.purpose = ShardRequest.PURPOSE_GET_TOP_GROUPS; sreq.params = new ModifiableSolrParams(rb.req.getParams()); // TODO: base on current params or original params? // don't pass through any shards param sreq.params.remove(ShardParams.SHARDS); // set the start (offset) to 0 for each shard request so we can properly merge // results from the start. if(rb.shards_start > -1) { // if the client set shards.start set this explicitly sreq.params.set(CommonParams.START,rb.shards_start); } else { sreq.params.set(CommonParams.START, "0"); } // TODO: should we even use the SortSpec? That's obtained from the QParser, and // perhaps we shouldn't attempt to parse the query at this level? // Alternate Idea: instead of specifying all these things at the upper level, // we could just specify that this is a shard request. if(rb.shards_rows > -1) { // if the client set shards.rows set this explicity sreq.params.set(CommonParams.ROWS,rb.shards_rows); } else { sreq.params.set(CommonParams.ROWS, rb.getSortSpec().getOffset() + rb.getSortSpec().getCount()); } // in this first phase, request only the unique key field // and any fields needed for merging. sreq.params.set(GroupParams.GROUP_DISTRIBUTED_FIRST, "true"); if ( (rb.getFieldFlags() & SolrIndexSearcher.GET_SCORES)!=0 || rb.getSortSpec().includesScore()) { sreq.params.set(CommonParams.FL, rb.req.getSchema().getUniqueKeyField().getName() + ",score"); } else { sreq.params.set(CommonParams.FL, rb.req.getSchema().getUniqueKeyField().getName()); } return new ShardRequest[] {sreq}; }
Example #13
Source File: RangeFacetRequest.java From lucene-solr with Apache License 2.0 | 4 votes |
public RangeFacetRequest(ResponseBuilder rb, String f) { super(rb, FacetParams.FACET_RANGE, f); IndexSchema schema = rb.req.getSchema(); this.schemaField = schema.getField(facetOn); SolrParams params = SolrParams.wrapDefaults(localParams, rb.req.getParams()); SolrParams required = new RequiredSolrParams(params); String methodStr = params.get(FacetParams.FACET_RANGE_METHOD); FacetParams.FacetRangeMethod method = (methodStr == null ? FacetParams.FacetRangeMethod.getDefault() : FacetParams.FacetRangeMethod.get(methodStr)); if ((schemaField.getType() instanceof DateRangeField) && method.equals(FacetParams.FacetRangeMethod.DV)) { // the user has explicitly selected the FacetRangeMethod.DV method log.warn("Range facet method '{}' is not supported together with field type '{}'. Will use method '{}' instead" , FacetParams.FacetRangeMethod.DV, DateRangeField.class, FacetParams.FacetRangeMethod.FILTER); method = FacetParams.FacetRangeMethod.FILTER; } if (method.equals(FacetParams.FacetRangeMethod.DV) && !schemaField.hasDocValues() && (schemaField.getType().isPointField())) { log.warn("Range facet method '{}' is not supported on PointFields without docValues. Will use method '{}' instead" , FacetParams.FacetRangeMethod.DV , FacetParams.FacetRangeMethod.FILTER); method = FacetParams.FacetRangeMethod.FILTER; } this.start = required.getFieldParam(facetOn, FacetParams.FACET_RANGE_START); this.end = required.getFieldParam(facetOn, FacetParams.FACET_RANGE_END); this.gap = required.getFieldParam(facetOn, FacetParams.FACET_RANGE_GAP); this.minCount = params.getFieldInt(facetOn, FacetParams.FACET_MINCOUNT, 0); this.include = FacetParams.FacetRangeInclude.parseParam (params.getFieldParams(facetOn, FacetParams.FACET_RANGE_INCLUDE)); this.hardEnd = params.getFieldBool(facetOn, FacetParams.FACET_RANGE_HARD_END, false); this.others = EnumSet.noneOf(FacetParams.FacetRangeOther.class); final String[] othersP = params.getFieldParams(facetOn, FacetParams.FACET_RANGE_OTHER); if (othersP != null && othersP.length > 0) { for (final String o : othersP) { others.add(FacetParams.FacetRangeOther.get(o)); } } this.groupFacet = params.getBool(GroupParams.GROUP_FACET, false); if (groupFacet && method.equals(FacetParams.FacetRangeMethod.DV)) { // the user has explicitly selected the FacetRangeMethod.DV method log.warn("Range facet method '{}' is not supported together with '{}'. Will use method '{}' instead" , FacetParams.FacetRangeMethod.DV, GroupParams.GROUP_FACET, FacetParams.FacetRangeMethod.FILTER); method = FacetParams.FacetRangeMethod.FILTER; } this.method = method; RangeEndpointCalculator<? extends Comparable<?>> calculator = createCalculator(); this.facetRanges = calculator.computeRanges(); this.gapObj = calculator.getGap(); this.startObj = calculator.getStart(); this.endObj = calculator.getComputedEnd(); }
Example #14
Source File: CursorPagingTest.java From lucene-solr with Apache License 2.0 | 4 votes |
/** verify expected error msgs from bad client behavior */ public void testBadInputs() throws Exception { // sometimes seed some data, othertimes use an empty index if (random().nextBoolean()) { assertU(adoc("id", "42", "str", "z", "float", "99.99", "int", "42")); assertU(adoc("id", "66", "str", "x", "float", "22.00", "int", "-66")); } else { assertU(commit()); } assertU(commit()); // empty, blank, or bogus cursor for (String c : new String[] { "", " ", "all the docs please!"}) { assertFail(params("q", "*:*", "sort", "id desc", CURSOR_MARK_PARAM, c), ErrorCode.BAD_REQUEST, "Unable to parse"); } // no id in sort assertFail(params("q", "*:*", "sort", "score desc", CURSOR_MARK_PARAM, CURSOR_MARK_START), ErrorCode.BAD_REQUEST, "uniqueKey field"); // _docid_ assertFail(params("q", "*:*", "sort", "_docid_ asc, id desc", CURSOR_MARK_PARAM, CURSOR_MARK_START), ErrorCode.BAD_REQUEST, "_docid_"); // using cursor w/ timeAllowed assertFail(params("q", "*:*", "sort", "id desc", CommonParams.TIME_ALLOWED, "1000", CURSOR_MARK_PARAM, CURSOR_MARK_START), ErrorCode.BAD_REQUEST, CommonParams.TIME_ALLOWED); // using cursor w/ grouping assertFail(params("q", "*:*", "sort", "id desc", GroupParams.GROUP, "true", GroupParams.GROUP_FIELD, "str", CURSOR_MARK_PARAM, CURSOR_MARK_START), ErrorCode.BAD_REQUEST, "Grouping"); }
Example #15
Source File: DistribCursorPagingTest.java From lucene-solr with Apache License 2.0 | 4 votes |
private void doBadInputTest() throws Exception { // sometimes seed some data, other times use an empty index if (random().nextBoolean()) { indexDoc(sdoc("id", "42", "str", "z", "float", "99.99", "int", "42")); indexDoc(sdoc("id", "66", "str", "x", "float", "22.00", "int", "-66")); } else { del("*:*"); } commit(); // empty, blank, or bogus cursor for (String c : new String[] { "", " ", "all the docs please!"}) { assertFail(params("q", "*:*", "sort", "id desc", CURSOR_MARK_PARAM, c), ErrorCode.BAD_REQUEST, "Unable to parse"); } // no id in sort assertFail(params("q", "*:*", "sort", "score desc", CURSOR_MARK_PARAM, CURSOR_MARK_START), ErrorCode.BAD_REQUEST, "uniqueKey field"); // _docid_ assertFail(params("q", "*:*", "sort", "_docid_ asc, id desc", CURSOR_MARK_PARAM, CURSOR_MARK_START), ErrorCode.BAD_REQUEST, "_docid_"); // using cursor w/ timeAllowed assertFail(params("q", "*:*", "sort", "id desc", CommonParams.TIME_ALLOWED, "1000", CURSOR_MARK_PARAM, CURSOR_MARK_START), ErrorCode.BAD_REQUEST, CommonParams.TIME_ALLOWED); // using cursor w/ grouping assertFail(params("q", "*:*", "sort", "id desc", GroupParams.GROUP, "true", GroupParams.GROUP_FIELD, "str", CURSOR_MARK_PARAM, CURSOR_MARK_START), ErrorCode.BAD_REQUEST, "Grouping"); }