org.apache.solr.common.params.FacetParams Java Examples
The following examples show how to use
org.apache.solr.common.params.FacetParams.
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: TestDymReSearcher.java From solr-researcher with Apache License 2.0 | 6 votes |
@Test public void testFacetAndHighlight() { assertQ(req(CommonParams.QT, "standardGoodSuggestion", CommonParams.Q, "foo:bobo AND foo:marley", SpellingParams.SPELLCHECK_COLLATE, "true", SpellingParams.SPELLCHECK_BUILD, "true", SpellingParams.SPELLCHECK_COUNT, "10", SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true", FacetParams.FACET, "true", FacetParams.FACET_FIELD, "foo", FacetParams.FACET_FIELD, "id", FacetParams.FACET_FIELD, "bar", FacetParams.FACET_QUERY, "id:[0 TO 20]", FacetParams.FACET_QUERY, "id:[1 TO 100]", HighlightParams.HIGHLIGHT, "true", HighlightParams.FIELDS, "foo", DymReSearcher.COMPONENT_NAME, "true", SpellCheckComponent.COMPONENT_NAME, "true") ,"//result[@name='spellchecked_response'][@numFound='7']" ,"//result[@name='response'][@numFound='0']" ,"//arr[@name='extended_spellchecker_suggestions']/str[1][.='foo:bob AND foo:marley']" ,"//lst[@name='spellchecked_facet_counts']/lst[@name='facet_fields']/lst[@name='foo']/int[@name='bob'][.='7']" ,"//lst[@name='spellchecked_facet_counts']/lst[@name='facet_fields']/lst[@name='foo']/int[@name='marley'][.='7']" ,"//lst[@name='spellchecked_highlighting']/lst[@name='2']/arr[@name='foo']/str[1]"); }
Example #2
Source File: LegacyFacet.java From lucene-solr with Apache License 2.0 | 6 votes |
Map<String,Object> getLegacy() { subFacets = parseSubFacets(params); String[] queries = params.getParams(FacetParams.FACET_QUERY); if (queries != null) { for (String q : queries) { addQueryFacet(q); } } String[] fields = params.getParams(FacetParams.FACET_FIELD); if (fields != null) { for (String field : fields) { addFieldFacet(field); } } String[] ranges = params.getParams(FacetParams.FACET_RANGE); if (ranges != null) { for (String range : ranges) { addRangeFacet(range); } } // SolrCore.log.error("###################### JSON FACET:" + json); return json; }
Example #3
Source File: SimpleFacets.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Computes the term->count counts for the specified term values relative to the * * @param field the name of the field to compute term counts against * @param parsed contains the docset to compute term counts relative to * @param terms a list of term values (in the specified field) to compute the counts for */ protected NamedList<Integer> getListedTermCounts(String field, final ParsedParams parsed, List<String> terms) throws IOException { final String sort = parsed.params.getFieldParam(field, FacetParams.FACET_SORT, "empty"); final SchemaField sf = searcher.getSchema().getField(field); final FieldType ft = sf.getType(); final DocSet baseDocset = parsed.docs; final NamedList<Integer> res = new NamedList<>(); Stream<String> inputStream = terms.stream(); if (sort.equals(FacetParams.FACET_SORT_INDEX)) { // it might always make sense inputStream = inputStream.sorted(); } Stream<SimpleImmutableEntry<String,Integer>> termCountEntries = inputStream .map((term) -> new SimpleImmutableEntry<>(term, numDocs(term, sf, ft, baseDocset))); if (sort.equals(FacetParams.FACET_SORT_COUNT)) { termCountEntries = termCountEntries.sorted(Collections.reverseOrder(Map.Entry.comparingByValue())); } termCountEntries.forEach(e -> res.add(e.getKey(), e.getValue())); return res; }
Example #4
Source File: LegacyFacet.java From lucene-solr with Apache License 2.0 | 6 votes |
protected void addRangeFacet(String field) { parseParams(FacetParams.FACET_RANGE, field); Map<String,Object> cmd = new HashMap<String,Object>(5); Map<String,Object> type = new HashMap<String,Object>(1); type.put("range", cmd); String f = key; cmd.put("field", facetValue); cmd.put("start", required.getFieldParam(f,FacetParams.FACET_RANGE_START)); cmd.put("end", required.getFieldParam(f,FacetParams.FACET_RANGE_END)); cmd.put("gap", required.getFieldParam(f, FacetParams.FACET_RANGE_GAP)); String[] p = params.getFieldParams(f, FacetParams.FACET_RANGE_OTHER); if (p != null) cmd.put("other", p.length==1 ? p[0] : Arrays.asList(p)); p = params.getFieldParams(f, FacetParams.FACET_RANGE_INCLUDE); if (p != null) cmd.put("include", p.length==1 ? p[0] : Arrays.asList(p)); final int mincount = params.getFieldInt(f,FacetParams.FACET_MINCOUNT, 0); cmd.put("mincount", mincount); boolean hardend = params.getFieldBool(f,FacetParams.FACET_RANGE_HARD_END,false); if (hardend) cmd.put("hardend", hardend); addSub(key, type); handleSubs(cmd); }
Example #5
Source File: SimpleFacetsTest.java From lucene-solr with Apache License 2.0 | 6 votes |
private ModifiableSolrParams getRandomParamsInt() { String field = new String[]{"range_facet_l_dv", "range_facet_i_dv", "range_facet_l", "duration_i1", "id_i1"}[random().nextInt(5)]; ModifiableSolrParams params = new ModifiableSolrParams(); Integer[] values = new Integer[2]; do { values[0] = random().nextInt(3000) * (random().nextBoolean()?-1:1); values[1] = random().nextInt(3000) * (random().nextBoolean()?-1:1); } while (values[0].equals(values[1])); Arrays.sort(values); long gapNum = Math.max(1, random().nextInt(3000)); params.add(FacetParams.FACET_RANGE_START, String.valueOf(values[0])); params.add(FacetParams.FACET_RANGE_END, String.valueOf(values[1])); params.add(FacetParams.FACET_RANGE_GAP, String.format(Locale.ROOT, "+%d", gapNum)); addCommonRandomRangeParams(params); params.add(FacetParams.FACET_RANGE, field); return params; }
Example #6
Source File: SolrQuery.java From lucene-solr with Apache License 2.0 | 6 votes |
/** enable/disable faceting. * * @param b flag to indicate faceting should be enabled. <br> if b==false, removes all other faceting parameters * @return Current reference (<i>this</i>) */ public SolrQuery setFacet(boolean b) { if (b) { this.set(FacetParams.FACET, true); } else { this.remove(FacetParams.FACET); this.remove(FacetParams.FACET_MINCOUNT); this.remove(FacetParams.FACET_FIELD); this.remove(FacetParams.FACET_LIMIT); this.remove(FacetParams.FACET_MISSING); this.remove(FacetParams.FACET_OFFSET); this.remove(FacetParams.FACET_PREFIX); this.remove(FacetParams.FACET_QUERY); this.remove(FacetParams.FACET_SORT); this.remove(FacetParams.FACET_ZEROS); this.remove(FacetParams.FACET_PREFIX); // does not include the individual fields... this.remove(FacetParams.FACET_INTERVAL); // does not remove interval parameters } return this; }
Example #7
Source File: FacetRangeMerger.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override Map<String, Object> getRefinementSpecial(Context mcontext, Map<String, Object> refinement, Collection<String> tagsWithPartial) { if (!tagsWithPartial.isEmpty()) { // Since 'other' buckets will always be included, we only need to worry about subfacets being partial. refinement = getRefinementSpecial(mcontext, refinement, tagsWithPartial, beforeBucket, FacetParams.FacetRangeOther.BEFORE.toString()); refinement = getRefinementSpecial(mcontext, refinement, tagsWithPartial, afterBucket, FacetParams.FacetRangeOther.AFTER.toString()); refinement = getRefinementSpecial(mcontext, refinement, tagsWithPartial, betweenBucket, FacetParams.FacetRangeOther.BETWEEN.toString()); // if we need an actual end to compute either of these buckets, // and it's been returned to us by at least one shard // send it back as part of the refinement request if ( (!freq.hardend) && actual_end != null && refinement != null && (refinement.containsKey(FacetParams.FacetRangeOther.AFTER.toString()) || refinement.containsKey(FacetParams.FacetRangeOther.BETWEEN.toString())) ) { refinement.put("_actual_end", actual_end); } } return refinement; }
Example #8
Source File: FacetComponent.java From lucene-solr with Apache License 2.0 | 6 votes |
protected void fillParams(ResponseBuilder rb, SolrParams params, String field) { this.field = field; this.ftype = rb.req.getSchema().getFieldTypeNoEx(this.field); this.offset = params.getFieldInt(field, FacetParams.FACET_OFFSET, 0); this.limit = params.getFieldInt(field, FacetParams.FACET_LIMIT, 100); Integer mincount = params.getFieldInt(field, FacetParams.FACET_MINCOUNT); if (mincount == null) { Boolean zeros = params.getFieldBool(field, FacetParams.FACET_ZEROS); // mincount = (zeros!=null && zeros) ? 0 : 1; mincount = (zeros != null && !zeros) ? 1 : 0; // current default is to include zeros. } this.minCount = mincount; this.missing = params.getFieldBool(field, FacetParams.FACET_MISSING, false); // default to sorting by count if there is a limit. this.sort = params.getFieldParam(field, FacetParams.FACET_SORT, (limit > 0 ? FacetParams.FACET_SORT_COUNT : FacetParams.FACET_SORT_INDEX)); if (this.sort.equals(FacetParams.FACET_SORT_COUNT_LEGACY)) { this.sort = FacetParams.FACET_SORT_COUNT; } else if (this.sort.equals(FacetParams.FACET_SORT_INDEX_LEGACY)) { this.sort = FacetParams.FACET_SORT_INDEX; } this.prefix = params.getFieldParam(field, FacetParams.FACET_PREFIX); }
Example #9
Source File: FacetComponent.java From lucene-solr with Apache License 2.0 | 6 votes |
private void removeRangeFacetsUnderLimits(ResponseBuilder rb) { if (rb.stage != ResponseBuilder.STAGE_EXECUTE_QUERY) { return; } FacetInfo fi = rb._facetInfo; for (Map.Entry<String, RangeFacetRequest.DistribRangeFacet> entry : fi.rangeFacets.entrySet()) { final String field = entry.getKey(); final RangeFacetRequest.DistribRangeFacet rangeFacet = entry.getValue(); int minCount = rb.req.getParams().getFieldInt(field, FacetParams.FACET_MINCOUNT, 0); if (minCount == 0) { continue; } rangeFacet.removeRangeFacetsUnderLimits(minCount); } }
Example #10
Source File: SimpleFacets.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Create a new bytes ref filter for filtering facet terms. If more than one filter is * applicable the applicable filters will be returned as an {@link Predicate#and(Predicate)} * of all such filters. * * @param field the field to check for facet term filters * @param params the request parameter object * @return A predicate for filtering terms or null if no filters are applicable. */ protected Predicate<BytesRef> newBytesRefFilter(String field, SolrParams params) { final String contains = params.getFieldParam(field, FacetParams.FACET_CONTAINS); Predicate<BytesRef> finalFilter = null; if (contains != null) { final boolean containsIgnoreCase = params.getFieldBool(field, FacetParams.FACET_CONTAINS_IGNORE_CASE, false); finalFilter = new SubstringBytesRefFilter(contains, containsIgnoreCase); } final String regex = params.getFieldParam(field, FacetParams.FACET_MATCHES); if (regex != null) { final RegexBytesRefFilter regexBytesRefFilter = new RegexBytesRefFilter(regex); finalFilter = (finalFilter == null) ? regexBytesRefFilter : finalFilter.and(regexBytesRefFilter); } final Predicate<BytesRef> excludeFilter = newExcludeBytesRefFilter(field, params); if (excludeFilter != null) { finalFilter = (finalFilter == null) ? excludeFilter : finalFilter.and(excludeFilter); } return finalFilter; }
Example #11
Source File: SimpleFacets.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Create a new bytes ref filter for excluding facet terms. * * This method by default uses the {@link FacetParams#FACET_EXCLUDETERMS} parameter * but custom SimpleFacets classes could use a different implementation. * * @param field the field to check for facet term filters * @param params the request parameter object * @return A predicate for filtering terms or null if no filters are applicable. */ protected Predicate<BytesRef> newExcludeBytesRefFilter(String field, SolrParams params) { final String exclude = params.getFieldParam(field, FacetParams.FACET_EXCLUDETERMS); if (exclude == null) { return null; } final Set<String> excludeTerms = new HashSet<>(StrUtils.splitSmart(exclude, ",", true)); return new Predicate<BytesRef>() { @Override public boolean test(BytesRef bytesRef) { return !excludeTerms.contains(bytesRef.utf8ToString()); } }; }
Example #12
Source File: TestFaceting.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testFacetOverPointFieldWithMinCount0() { String field = "f_" + new String[]{"i","l","f","d"}[random().nextInt(4)] + "_p"; String expectedWarning = "Raising facet.mincount from 0 to 1, because field " + field + " is Points-based."; SolrQueryRequest req = req("q", "id:1.0", FacetParams.FACET, "true", FacetParams.FACET_FIELD, field, FacetParams.FACET_MINCOUNT, "0"); assertQ(req , "/response/lst[@name='responseHeader']/arr[@name='warnings']/str[.='" + expectedWarning + "']"); field = "f_" + new String[]{"is","ls","fs","ds"}[random().nextInt(4)] + "_p"; expectedWarning = "Raising facet.mincount from 0 to 1, because field " + field + " is Points-based."; req = req("q", "id:1.0", FacetParams.FACET, "true", FacetParams.FACET_FIELD, field, FacetParams.FACET_MINCOUNT, "0"); assertQ(req , "/response/lst[@name='responseHeader']/arr[@name='warnings']/str[.='" + expectedWarning + "']"); }
Example #13
Source File: FacetPivotSmallTest.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testPivotFacetLimit() throws Exception { index(); final ModifiableSolrParams params = new ModifiableSolrParams(); params.add("q", "*:*"); params.add("facet", "true"); params.add("facet.pivot", "place_t,company_t"); params.set(FacetParams.FACET_SORT, FacetParams.FACET_SORT_COUNT); params.set(FacetParams.FACET_LIMIT, 2); final String facetPivotPrefix = "//lst[@name='facet_counts']/lst[@name='facet_pivot']/arr[@name='place_t,company_t']/lst"; SolrQueryRequest req = req(params); assertQ(req, facetPivotPrefix + "/str[@name='field'][.='place_t']", // dublin facetPivotPrefix + "[str[@name='value'][.='dublin']]/arr[@name='pivot']/lst[1]/str[@name='value'][.='microsoft']", facetPivotPrefix + "[str[@name='value'][.='dublin']]/arr[@name='pivot']/lst[1]/int[@name='count'][.=4]", facetPivotPrefix + "[str[@name='value'][.='dublin']]/arr[@name='pivot']/lst[2]/str[@name='value'][.='polecat']", facetPivotPrefix + "[str[@name='value'][.='dublin']]/arr[@name='pivot']/lst[2]/int[@name='count'][.=4]", // london facetPivotPrefix + "[str[@name='value'][.='london']]/arr[@name='pivot']/lst[1]/str[@name='value'][.='null']", facetPivotPrefix + "[str[@name='value'][.='london']]/arr[@name='pivot']/lst[1]/int[@name='count'][.=3]", facetPivotPrefix + "[str[@name='value'][.='london']]/arr[@name='pivot']/lst[2]/str[@name='value'][.='polecat']", facetPivotPrefix + "[str[@name='value'][.='london']]/arr[@name='pivot']/lst[2]/int[@name='count'][.=3]" ); }
Example #14
Source File: TreeFacetComponent.java From BioSolr with Apache License 2.0 | 5 votes |
private void addTreeFieldsToFacets(ResponseBuilder rb) throws SyntaxError { String[] ftFields = rb.req.getParams().getParams(FACET_TREE_FIELD); if (ftFields == null || ftFields.length == 0) { LOGGER.warn("No facet tree fields specified - ignoring facet trees"); } else { // Take a modifiable copy of the incoming params ModifiableSolrParams params = new ModifiableSolrParams(rb.req.getParams()); // Put the original facet fields (if any) into a Set Set<String> facetFields = new LinkedHashSet<>(); if (params.getParams(FacetParams.FACET_FIELD) != null) { facetFields.addAll(Arrays.asList(params.getParams(FacetParams.FACET_FIELD))); } // Add the facet tree fields for (String ftField : ftFields) { // Parse the facet tree field, so we only add the field value, // rather than the whole string (ensure it's unique) facetFields.add(QueryParsing.getLocalParams(ftField, params).get(QueryParsing.V)); } // Add the (possibly) new facet fields params.set(FacetParams.FACET_FIELD, facetFields.toArray(new String[facetFields.size()])); // Re-set the params in the request rb.req.setParams(params); } }
Example #15
Source File: FTestCase.java From SolRDF with Apache License 2.0 | 5 votes |
@Test public void isntHybrid() { final SolrQueryRequest request = mock(SolrQueryRequest.class); final ModifiableSolrParams [] listOfParams = { new ModifiableSolrParams(), new ModifiableSolrParams().add(FacetParams.FACET, "false"), }; for (final ModifiableSolrParams params : listOfParams) { when(request.getParams()).thenReturn(params); assertFalse(F.isHybrid(request)); reset(request); } }
Example #16
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 #17
Source File: PivotFacetFieldValueCollection.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Returns the appropriate sub-list of the explicit values that need to be refined, * based on the {@link FacetParams#FACET_OFFSET} & {@link FacetParams#FACET_LIMIT} * for this field. * * @see #getExplicitValuesList * @see List#subList */ public List<PivotFacetValue> getNextLevelValuesToRefine() { final int numRefinableValues = getExplicitValuesListSize(); if (numRefinableValues < facetFieldOffset) { return Collections.<PivotFacetValue>emptyList(); } final int offsetPlusCount = (facetFieldLimit >= 0) ? Math.min(facetFieldLimit + facetFieldOffset, numRefinableValues) : numRefinableValues; if (1 < facetFieldMinimumCount && facetFieldSort.equals(FacetParams.FACET_SORT_INDEX)) { // we have to skip any values that (still) don't meet the mincount // // TODO: in theory we could avoid this extra check by trimming sooner (SOLR-6331) // but since that's a destructive op that blows away the `valuesMap` which we (might?) still need // (and pre-emptively skips the offsets) we're avoiding re-working that optimization // for now until/unless someone gives it more careful thought... final List<PivotFacetValue> results = new ArrayList<>(numRefinableValues); for (PivotFacetValue pivotValue : explicitValues) { if (pivotValue.getCount() >= facetFieldMinimumCount) { results.add(pivotValue); if (numRefinableValues <= results.size()) { break; } } } return results; } // in the non "sort==count OR mincount==1" situation, we can just return the first N values // because any viable candidate is already in the top N return getExplicitValuesList().subList(facetFieldOffset, offsetPlusCount); }
Example #18
Source File: TestDymReSearcher.java From solr-researcher with Apache License 2.0 | 5 votes |
@Test public void testOriginalAndSpellcheckedFacet() { assertQ(req(CommonParams.QT, "standardGoodSuggestionAllowSomeOriginalResults", CommonParams.Q, "foo:elvos OR foo:presley", SpellingParams.SPELLCHECK_COLLATE, "true", SpellingParams.SPELLCHECK_BUILD, "true", SpellingParams.SPELLCHECK_COUNT, "10", SpellingParams.SPELLCHECK_EXTENDED_RESULTS, "true", FacetParams.FACET, "true", FacetParams.FACET_FIELD, "foo", FacetParams.FACET_FIELD, "id", FacetParams.FACET_FIELD, "bar", FacetParams.FACET_QUERY, "id:[0 TO 20]", FacetParams.FACET_QUERY, "id:[1 TO 100]", HighlightParams.HIGHLIGHT, "true", HighlightParams.FIELDS, "foo", DymReSearcher.COMPONENT_NAME, "true", SpellCheckComponent.COMPONENT_NAME, "true") ,"//result[@name='spellchecked_response'][@numFound='3']" ,"//result[@name='response'][@numFound='1']" ,"//arr[@name='extended_spellchecker_suggestions']/str[1][.='foo:elvis OR foo:presley']" // check spellchecked facets: ,"//lst[@name='spellchecked_facet_counts']/lst[@name='facet_fields']/lst[@name='foo']/int[@name='elvi'][.='3']" ,"//lst[@name='spellchecked_facet_counts']/lst[@name='facet_fields']/lst[@name='foo']/int[@name='presley'][.='1']" ,"//lst[@name='spellchecked_facet_counts']/lst[@name='facet_fields']/lst[@name='foo']/int[@name='2'][.='1']" // check original facets: ,"//lst[@name='facet_counts']/lst[@name='facet_fields']/lst[@name='foo']/int[@name='elvi'][.='1']" ,"//lst[@name='facet_counts']/lst[@name='facet_fields']/lst[@name='foo']/int[@name='presley'][.='1']" ); }
Example #19
Source File: LegacyFacet.java From lucene-solr with Apache License 2.0 | 5 votes |
protected void parseParams(String type, String param) { facetValue = param; key = param; try { localParams = QueryParsing.getLocalParams(param, orig); if (localParams == null) { params = orig; required = new RequiredSolrParams(params); // setupStats(); return; } params = SolrParams.wrapDefaults(localParams, orig); required = new RequiredSolrParams(params); // 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); // setupStats(); } catch (SyntaxError e) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e); } }
Example #20
Source File: DistributedFacetPivotSmallTest.java From lucene-solr with Apache License 2.0 | 5 votes |
private void testNegativeFacetQuery() throws Exception { // this should not hang facet.query under the pivot SolrParams params = params("q", "*:*", "rows", "0", "stats", "true", "facet.query", "{!tag=ttt}price_ti:[25 TO 100]", "facet", "true", "facet.pivot", "{!query=t}place_t,company_t"); QueryResponse rsp = query(params); assertNullFacetTypeInsidePivot(FacetParams.FACET_QUERY, rsp.getFacetPivot().get("place_t,company_t")); params = params("q", "*:*", "rows", "0", "stats", "true", "facet", "true", "facet.pivot", "{!query=t}place_t,company_t"); rsp = query(params); assertNullFacetTypeInsidePivot(FacetParams.FACET_QUERY, rsp.getFacetPivot().get("place_t,company_t")); params = params("q", "*:*", "rows", "0", "facet.query", "{!tag=t}price_ti:[25 TO 100]", "hang", "", // empty "facet", "true", "facet.pivot", "{!query=$hang}place_t,company_t"); rsp = query(params); assertNullFacetTypeInsidePivot(FacetParams.FACET_QUERY, rsp.getFacetPivot().get("place_t,company_t")); params = params("q", "*:*", "rows", "0", "facet.query", "{!tag=t}price_ti:[25 TO 100]", "hang", "price_ti:[0 TO 20]", // with a query "facet", "true", "facet.pivot", "{!query=$hang}place_t,company_t"); rsp = query(params); // we aren't going to start calculating facet query unless the query is specified with a 'facet.query' param // hence hanging an arbitrary query shouldn't work assertNullFacetTypeInsidePivot(FacetParams.FACET_QUERY, rsp.getFacetPivot().get("place_t,company_t")); }
Example #21
Source File: SimpleFacets.java From lucene-solr with Apache License 2.0 | 5 votes |
public static void checkMincountOnExists(String fieldName, int mincount) { if (mincount > 1) { throw new SolrException (ErrorCode.BAD_REQUEST, FacetParams.FACET_MINCOUNT + "="+mincount+" exceed 1 that's not supported with " + FacetParams.FACET_EXISTS + "=true for " + fieldName ); } }
Example #22
Source File: SpatialHeatmapFacets.java From lucene-solr with Apache License 2.0 | 5 votes |
private static FacetRequest createHeatmapRequest(String fieldKey, String fieldName, ResponseBuilder rb, SolrParams params) { Map<String, Object> jsonFacet = new HashMap<>(); jsonFacet.put("type", "heatmap"); jsonFacet.put("field", fieldName); // jsonFacets has typed values, unlike SolrParams which is all string jsonFacet.put(FacetHeatmap.GEOM_PARAM, params.getFieldParam(fieldKey, FacetParams.FACET_HEATMAP_GEOM)); jsonFacet.put(FacetHeatmap.LEVEL_PARAM, params.getFieldInt(fieldKey, FacetParams.FACET_HEATMAP_LEVEL)); jsonFacet.put(FacetHeatmap.DIST_ERR_PCT_PARAM, params.getFieldDouble(fieldKey, FacetParams.FACET_HEATMAP_DIST_ERR_PCT)); jsonFacet.put(FacetHeatmap.DIST_ERR_PARAM, params.getFieldDouble(fieldKey, FacetParams.FACET_HEATMAP_DIST_ERR)); jsonFacet.put(FacetHeatmap.MAX_CELLS_PARAM, params.getFieldInt(fieldKey, FacetParams.FACET_HEATMAP_MAX_CELLS)); jsonFacet.put(FacetHeatmap.FORMAT_PARAM, params.getFieldParam(fieldKey, FacetParams.FACET_HEATMAP_FORMAT)); return FacetRequest.parseOneFacetReq(rb.req, jsonFacet); }
Example #23
Source File: TestQueryRelaxerComponent.java From solr-researcher with Apache License 2.0 | 5 votes |
@Test public void testFacet() { assertQ(req(CommonParams.QT, "dismax_relaxer", CommonParams.Q, "bi marley ", QueryRelaxerComponent.COMPONENT_NAME, "true", FacetComponent.COMPONENT_NAME, "true", FacetParams.FACET_FIELD, "id") ,"//result[@name='response'][@numFound='0']" ,"//arr[@name='relaxer_suggestions']/lst[1]/str[@name='relaxedQuery'][.='marley']" ,"//arr[@name='relaxer_suggestions']/lst[1]/lst[@name='relaxer_facet_counts']/lst[@name='facet_fields']/lst[@name='id']" ); }
Example #24
Source File: FacetComponent.java From lucene-solr with Apache License 2.0 | 5 votes |
public FacetBase(ResponseBuilder rb, String facetType, String facetStr) { this.facetType = facetType; this.facetStr = facetStr; try { this.localParams = QueryParsing.getLocalParams(facetStr, rb.req.getParams()); } catch (SyntaxError e) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e); } this.facetOn = facetStr; this.key = facetStr; if (localParams != null) { // remove local params unless it's a query if (!facetType.equals(FacetParams.FACET_QUERY)) { facetOn = localParams.get(CommonParams.VALUE); key = facetOn; } key = localParams.get(CommonParams.OUTPUT_KEY, key); String tagStr = localParams.get(CommonParams.TAG); this.tags = tagStr == null ? Collections.<String>emptyList() : StrUtils.splitSmart(tagStr,','); String threadStr = localParams.get(CommonParams.THREADS); this.threadCount = threadStr != null ? Integer.parseInt(threadStr) : -1; String excludeStr = localParams.get(CommonParams.EXCLUDE); if (StringUtils.isEmpty(excludeStr)) { this.excludeTags = Collections.emptyList(); } else { this.excludeTags = StrUtils.splitSmart(excludeStr,','); } } }
Example #25
Source File: AggregationWaitableTest.java From semantic-knowledge-graph with Apache License 2.0 | 5 votes |
@Test public void buildFacetParams(){ AggregationWaitable target = new AggregationWaitable(context, adapter, "query", "testField",0, 0); MapSolrParams actual = Deencapsulation.invoke(target, "buildFacetParams"); Assert.assertEquals("json".compareTo(actual.get("wt")), 0); Assert.assertEquals("1".compareTo(actual.get("facet.version")), 0); Assert.assertEquals("true".compareTo(actual.get(FacetParams.FACET)), 0); }
Example #26
Source File: FacetComponent.java From lucene-solr with Apache License 2.0 | 5 votes |
protected void fillParams(ResponseBuilder rb, SolrParams params, String field) { super.fillParams(rb, params, field); this.overrequestRatio = params.getFieldDouble(field, FacetParams.FACET_OVERREQUEST_RATIO, 1.5); this.overrequestCount = params.getFieldInt(field, FacetParams.FACET_OVERREQUEST_COUNT, 10); }
Example #27
Source File: SimpleFacetsTest.java From lucene-solr with Apache License 2.0 | 5 votes |
private void addCommonRandomRangeParams(ModifiableSolrParams params) { for (int i = 0; i < random().nextInt(2); i++) { params.add(FacetParams.FACET_RANGE_OTHER, FacetRangeOther.values()[random().nextInt(FacetRangeOther.values().length)].toString()); } if (random().nextBoolean()) { params.add(FacetParams.FACET_RANGE_INCLUDE, FacetRangeInclude.values()[random().nextInt(FacetRangeInclude.values().length)].toString()); } if (random().nextBoolean()) { params.add(FacetParams.FACET_MINCOUNT, String.valueOf(random().nextInt(10))); } params.add(FacetParams.FACET_RANGE_HARD_END, String.valueOf(random().nextBoolean())); }
Example #28
Source File: SpatialHeatmapFacets.java From lucene-solr with Apache License 2.0 | 5 votes |
/** Parses request to "HeatmapFacet" instances. */ public static LinkedHashMap<String,HeatmapFacet> distribParse(SolrParams params, ResponseBuilder rb) { final LinkedHashMap<String, HeatmapFacet> heatmapFacets = new LinkedHashMap<>(); final String[] heatmapFields = params.getParams(FacetParams.FACET_HEATMAP); if (heatmapFields != null) { for (String heatmapField : heatmapFields) { HeatmapFacet facet = new HeatmapFacet(rb, heatmapField); heatmapFacets.put(facet.getKey(), facet); } } return heatmapFacets; }
Example #29
Source File: SolrQueryTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testSettersGetters() { SolrQuery q = new SolrQuery("foo"); assertEquals(10, q.setFacetLimit(10).getFacetLimit()); assertEquals(10, q.setFacetMinCount(10).getFacetMinCount()); assertEquals("index", q.setFacetSort("index").getFacetSortString()); assertEquals(10, q.setHighlightSnippets(10).getHighlightSnippets()); assertEquals(10, q.setHighlightFragsize(10).getHighlightFragsize()); assertEquals(true, q.setHighlightRequireFieldMatch(true).getHighlightRequireFieldMatch()); assertEquals("foo", q.setHighlightSimplePre("foo").getHighlightSimplePre()); assertEquals("foo", q.setHighlightSimplePost("foo").getHighlightSimplePost()); assertEquals(true, q.setHighlight(true).getHighlight()); assertEquals("foo", q.setQuery("foo").getQuery()); assertEquals(10, q.setRows(10).getRows().intValue()); assertEquals(10, q.setStart(10).getStart().intValue()); assertEquals("foo", q.setRequestHandler("foo").getRequestHandler()); assertEquals(10, q.setTimeAllowed(10).getTimeAllowed().intValue()); // non-standard assertEquals("foo", q.setFacetPrefix("foo").get( FacetParams.FACET_PREFIX, null ) ); assertEquals("foo", q.setFacetPrefix("a", "foo").getFieldParam( "a", FacetParams.FACET_PREFIX, null ) ); assertEquals( Boolean.TRUE, q.setFacetMissing(Boolean.TRUE).getBool( FacetParams.FACET_MISSING ) ); assertEquals( Boolean.FALSE, q.setFacetMissing( Boolean.FALSE ).getBool( FacetParams.FACET_MISSING ) ); assertEquals( "true", q.setParam( "xxx", true ).getParams( "xxx" )[0] ); assertEquals( "x,y", q.setFields("x","y").getFields() ); assertEquals( "x,y,score", q.setIncludeScore(true).getFields() ); assertEquals( "x,y,score", q.setIncludeScore(true).getFields() ); // set twice on purpose assertEquals( "x,y", q.setIncludeScore(false).getFields() ); assertEquals( "x,y", q.setIncludeScore(false).getFields() ); // remove twice on purpose }
Example #30
Source File: SolrQueryTest.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testFacetInterval() { SolrQuery solrQuery = new SolrQuery(); solrQuery.addIntervalFacets("field1", new String[]{}); assertTrue(solrQuery.getBool(FacetParams.FACET)); assertEquals("field1", solrQuery.get(FacetParams.FACET_INTERVAL)); solrQuery.addIntervalFacets("field2", new String[]{"[1,10]"}); assertArrayEquals(new String[]{"field1", "field2"}, solrQuery.getParams(FacetParams.FACET_INTERVAL)); assertEquals("[1,10]", solrQuery.get("f.field2.facet.interval.set")); solrQuery.addIntervalFacets("field3", new String[]{"[1,10]", "(10,100]", "(100,1000]", "(1000,*]"}); assertArrayEquals(new String[]{"field1", "field2", "field3"}, solrQuery.getParams(FacetParams.FACET_INTERVAL)); assertArrayEquals(new String[]{"[1,10]", "(10,100]", "(100,1000]", "(1000,*]"}, solrQuery.getParams("f.field3.facet.interval.set")); //Validate adding more intervals for an existing field solrQuery.addIntervalFacets("field2", new String[]{"[10,100]"}); assertArrayEquals(new String[]{"[1,10]", "[10,100]"}, solrQuery.getParams("f.field2.facet.interval.set")); assertNull(solrQuery.removeIntervalFacets("field1")); assertArrayEquals(new String[]{"field2", "field3", "field2"}, solrQuery.getParams(FacetParams.FACET_INTERVAL)); assertNull(solrQuery.getParams("f.field1.facet.interval.set")); assertArrayEquals(new String[]{"[1,10]", "[10,100]"}, solrQuery.removeIntervalFacets("field2")); assertArrayEquals(new String[]{"field3"}, solrQuery.getParams(FacetParams.FACET_INTERVAL)); assertNull(solrQuery.getParams("f.field2.facet.interval.set")); assertArrayEquals(new String[]{"[1,10]", "(10,100]", "(100,1000]", "(1000,*]"}, solrQuery.removeIntervalFacets("field3")); assertNull(solrQuery.getParams(FacetParams.FACET_INTERVAL)); assertNull(solrQuery.getParams("f.field3.facet.interval.set")); }