List of usage examples for org.apache.solr.common.params ShardParams SHARDS_PURPOSE
String SHARDS_PURPOSE
To view the source code for org.apache.solr.common.params ShardParams SHARDS_PURPOSE.
Click Source Link
From source file:org.alfresco.solr.component.RewriteFacetParametersComponent.java
License:Open Source License
/** * Ensure the mincount for all given facets is at least 1 to prevent exposing sensitive buckets to users without permission. * * @param fixed The updated params object. * @param params The original params object. * @param paramName The name of the mincount parameter to rewrite (e.g. "facet.mincount" or "facet.pivot.mincount"). * @param fieldMappings A list of mappings from Alfresco property names to Solr field names. * @param req The Solr request/*w ww . j av a 2 s . c o m*/ */ protected void rewriteMincountFacetFieldOption(ModifiableSolrParams fixed, SolrParams params, String paramName, Map<String, String> fieldMappings, SolrQueryRequest req) { rewriteFacetFieldOptions(fixed, params, paramName, fieldMappings); String shardPurpose = req.getParams().get(ShardParams.SHARDS_PURPOSE); boolean isInitialDistributedRequest = (shardPurpose == null); /* * After the initial Search request, in case of Sharding the Solr node will build additional http requests to the other shards. * These requests may have specific parameters rewritten by Solr internally. * It's not recommended to rewrite them, because some side effect may happen. * Only the initial request parameters may be rewritten. * */ if (isInitialDistributedRequest) { // Update any existing mincount entries for facets. Map<String, Integer> updatedValues = new HashMap<>(); for (Iterator<String> renamedParameters = fixed.getParameterNamesIterator(); renamedParameters .hasNext();) { String solrParameter = renamedParameters.next(); if (solrParameter.endsWith("." + paramName)) { // If mincount is set then renamedParameters must be an integer. int value = Integer.valueOf(fixed.get(solrParameter)); // Don't directly edit the params while we're iterating through the entries. updatedValues.put(solrParameter, Math.max(value, 1)); } } // Now we've finished iterating, update the fixed parameters. for (Map.Entry<String, Integer> updatedParameterValues : updatedValues.entrySet()) { fixed.set(updatedParameterValues.getKey(), updatedParameterValues.getValue()); } String paramValue = params.get(paramName); int value = 0; if (paramValue != null) { value = Integer.valueOf(paramValue); } fixed.set(paramName, Math.max(value, 1)); } }
From source file:org.alfresco.solr.component.RewriteFacetParametersComponent.java
License:Open Source License
/** * Update the facet fields to use Solr field names rather than ACS property names. * * @param fixed The updated params object. * @param params The original params object. * @param paramName The name of the mincount parameter to rewrite (e.g. "facet.mincount" or "facet.pivot.mincount"). * @param fieldMappings A list of mappings from Alfresco property names to Solr field names. * @param req The original request./* ww w . j a v a 2 s .c o m*/ * @return An array of the facet field names. */ private List<String> rewriteFacetFieldList(ModifiableSolrParams fixed, SolrParams params, String paramName, Map<String, String> fieldMappings, SolrQueryRequest req) { String shardPurpose = req.getParams().get(ShardParams.SHARDS_PURPOSE); boolean isRefinementRequest = (shardPurpose != null) ? (shardPurpose.equals(String.valueOf(ShardRequest.PURPOSE_REFINE_FACETS))) || (shardPurpose.equals(String.valueOf(ShardRequest.PURPOSE_REFINE_PIVOT_FACETS))) : false; String[] facetFieldsOrig = params.getParams(paramName); List<String> facetFieldList = new ArrayList<>(); if (facetFieldsOrig != null) { ArrayList<String> newFacetFields = new ArrayList<String>(); for (String facetFields : facetFieldsOrig) { StringBuilder commaSeparated = new StringBuilder(); StringBuilder mapping = new StringBuilder(); StringBuilder unmapped = new StringBuilder(); String[] fields = parseFacetField(facetFields); for (String field : fields) { String prefix = ""; field = field.trim(); if (field.endsWith("()")) { // skip facet functions continue; } if (field.startsWith("{!") && !(isRefinementRequest)) { int index = field.indexOf("}"); if ((index > 0) && (index < (field.length() - 1))) { prefix = field.substring(0, index + 1); field = field.substring(index + 1); } } boolean noMappingIsRequired = req.getSchema().getFieldOrNull(field) != null || isRefinementRequest; if (noMappingIsRequired) { if (commaSeparated.length() > 0) { commaSeparated.append(","); mapping.append(","); unmapped.append(","); } commaSeparated.append(prefix).append(field); mapping.append(field); unmapped.append(field); facetFieldList.add(field); } else { String mappedField = AlfrescoSolrDataModel.getInstance().mapProperty(field, FieldUse.FACET, req); if (commaSeparated.length() > 0) { commaSeparated.append(","); mapping.append(","); unmapped.append(","); } commaSeparated.append(prefix).append(mappedField); mapping.append(mappedField); unmapped.append(field); facetFieldList.add(mappedField); } } if (!facetFields.equals(commaSeparated.toString())) { fieldMappings.put(unmapped.toString(), mapping.toString()); } if (commaSeparated.length() > 0) { newFacetFields.add(commaSeparated.toString()); } } fixed.set(paramName, newFacetFields.toArray(new String[newFacetFields.size()])); } return facetFieldList; }
From source file:org.alfresco.solr.component.RewriteFacetParametersComponentTest.java
License:Open Source License
/** Check that if no mincount is supplied for a field facet then it gets defaulted to 1. */ @Test/*from w w w. j a v a 2 s. c o m*/ public void rewriteMincountFacetFieldOption_mincountMissing_shouldSetGenericMinCountToOne() { // There are no existing facet parameters. ModifiableSolrParams fixed = new ModifiableSolrParams(); when(mockParams.getParameterNamesIterator()).thenReturn(Iterators.empty()); when(mockParams.get(ShardParams.SHARDS_PURPOSE)).thenReturn(null); Map<String, String> fieldMappings = new HashMap<>(); // Call the method under test. rewriteFacetParametersComponent.rewriteMincountFacetFieldOption(fixed, mockParams, "facet.mincount", fieldMappings, mockRequest); // Check that the mincount is set to 1. String actual = fixed.get("facet.mincount"); assertEquals("Expected the existing mincount to be preserved.", "1", actual); }
From source file:org.alfresco.solr.component.RewriteFacetParametersComponentTest.java
License:Open Source License
/** Check that if the mincount is set as 0 then it is updated to be 1. */ @Test/*from ww w . ja va 2 s . c o m*/ public void rewriteMincountFacetFieldOption_mincountSetZero_shouldSetMincountToOne() { ModifiableSolrParams fixed = new ModifiableSolrParams(); // The user has tried to set the mincount to zero. when(mockParams.getParameterNamesIterator()).thenReturn(asList("facet.mincount").iterator()); when(mockParams.get("facet.mincount")).thenReturn("0"); when(mockParams.get(ShardParams.SHARDS_PURPOSE)).thenReturn(null); Map<String, String> fieldMappings = new HashMap<>(); // Call the method under test. rewriteFacetParametersComponent.rewriteMincountFacetFieldOption(fixed, mockParams, "facet.mincount", fieldMappings, mockRequest); // Check that the mincount is set to 1 and the field name is converted to the format stored by Solr. String actualCount = fixed.get("facet.mincount"); assertEquals("Expected the mincount to be 1.", "1", actualCount); }
From source file:org.alfresco.solr.component.RewriteFacetParametersComponentTest.java
License:Open Source License
@Test public void rewriteShardedRequestParameters_mincountSetZero_shouldKeepMincountToZero() { ModifiableSolrParams fixed = new ModifiableSolrParams(); // The user has tried to set the mincount to zero. when(mockParams.getParameterNamesIterator()).thenReturn(asList("facet.mincount").iterator()); when(mockParams.get("facet.mincount")).thenReturn("0"); when(mockParams.get(ShardParams.SHARDS_PURPOSE)) .thenReturn(String.valueOf(ShardRequest.PURPOSE_GET_FACETS)); Map<String, String> fieldMappings = new HashMap<>(); // Call the method under test. rewriteFacetParametersComponent.rewriteMincountFacetFieldOption(fixed, mockParams, "facet.mincount", fieldMappings, mockRequest); // Check that the mincount is set to 1 and the field name is converted to the format stored by Solr. String actualCount = fixed.get("facet.mincount"); assertEquals("Expected no fixed value", null, actualCount); }
From source file:org.alfresco.solr.component.RewriteFacetParametersComponentTest.java
License:Open Source License
@Test public void rewriteMincountFacetFieldOption_mincountSetTwo_shouldKeepIt() { ModifiableSolrParams fixed = new ModifiableSolrParams(); // The user has tried to set the mincount to zero. when(mockParams.getParameterNamesIterator()).thenReturn(asList("facet.mincount").iterator()); when(mockParams.get("facet.mincount")).thenReturn("2"); when(mockParams.get(ShardParams.SHARDS_PURPOSE)).thenReturn(null); Map<String, String> fieldMappings = new HashMap<>(); // Call the method under test. rewriteFacetParametersComponent.rewriteMincountFacetFieldOption(fixed, mockParams, "facet.mincount", fieldMappings, mockRequest); // Check that the mincount is set to 1 and the field name is converted to the format stored by Solr. String actualCount = fixed.get("facet.mincount"); assertEquals("Expected the mincount to be 2.", "2", actualCount); }
From source file:org.alfresco.solr.component.RewriteFacetParametersComponentTest.java
License:Open Source License
@Test public void rewriteMincountFacetFieldOption_perFieldMincountSetZero_shouldSetPerFieldMincountAndMincountToOne() { ModifiableSolrParams fixed = new ModifiableSolrParams(); // The user has tried to set the mincount to zero. when(mockParams.getParameterNamesIterator()) .thenReturn(asList("f.NAME.facet.mincount", "f.CONTENT.facet.mincount").iterator()); when(mockParams.getParams("f.NAME.facet.mincount")).thenReturn(new String[] { "0" }); when(mockParams.getParams("f.CONTENT.facet.mincount")).thenReturn(new String[] { "0" }); when(mockParams.get(ShardParams.SHARDS_PURPOSE)).thenReturn(null); Map<String, String> fieldMappings = ImmutableMap.of("NAME", "{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}name", "CONTENT", "{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}content"); // Call the method under test. rewriteFacetParametersComponent.rewriteMincountFacetFieldOption(fixed, mockParams, "facet.mincount", fieldMappings, mockRequest); // Check that the mincount is set to 1 and the field name is converted to the format stored by Solr. String actualNameCount = fixed.get( "f.{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}name.facet.mincount"); assertEquals("Expected the mincount to be 1.", "1", actualNameCount); String actualContentCount = fixed.get( "f.{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}content.facet.mincount"); assertEquals("Expected the mincount to be 1.", "1", actualContentCount); String actualCount = fixed.get("facet.mincount"); assertEquals("Expected the mincount to be 1.", "1", actualCount); }
From source file:org.alfresco.solr.component.RewriteFacetParametersComponentTest.java
License:Open Source License
/** Check that if the mincount is set as 0 then it is updated to be 1. */ @Test//from w w w . ja v a 2 s .co m public void rewriteMincountFacetFieldOption_perFieldMincountSetZero_shouldSetPerFieldMincountToOne() { ModifiableSolrParams fixed = new ModifiableSolrParams(); // The user has tried to set the mincount to zero. when(mockParams.getParameterNamesIterator()) .thenReturn(asList("f.NAME.facet.mincount", "f.CONTENT.facet.mincount").iterator()); when(mockParams.getParams("f.NAME.facet.mincount")).thenReturn(new String[] { "0" }); when(mockParams.getParams("f.CONTENT.facet.mincount")).thenReturn(new String[] { "0" }); when(mockParams.get(ShardParams.SHARDS_PURPOSE)).thenReturn(null); Map<String, String> fieldMappings = ImmutableMap.of("NAME", "{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}name", "CONTENT", "{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}content"); // Call the method under test. rewriteFacetParametersComponent.rewriteMincountFacetFieldOption(fixed, mockParams, "facet.mincount", fieldMappings, mockRequest); // Check that the mincount is set to 1 and the field name is converted to the format stored by Solr. String actualNameCount = fixed.get( "f.{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}name.facet.mincount"); assertEquals("Expected the mincount to be 1.", "1", actualNameCount); String actualContentCount = fixed.get( "f.{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}content.facet.mincount"); assertEquals("Expected the mincount to be 1.", "1", actualContentCount); }
From source file:org.alfresco.solr.component.RewriteFacetParametersComponentTest.java
License:Open Source License
/** Check that if the user supplies a mincount of 2 then this is not changed. */ @Test/*ww w .jav a 2 s . c o m*/ public void rewriteMincountFacetFieldOption_perFieldMincountSetTwo_shouldKeepIt() { ModifiableSolrParams fixed = new ModifiableSolrParams(); // The user has tried to set the mincount to zero. when(mockParams.getParameterNamesIterator()) .thenReturn(asList("f.NAME.facet.mincount", "f.CONTENT.facet.mincount").iterator()); when(mockParams.getParams("f.NAME.facet.mincount")).thenReturn(new String[] { "2" }); when(mockParams.getParams("f.CONTENT.facet.mincount")).thenReturn(new String[] { "0" }); when(mockParams.get(ShardParams.SHARDS_PURPOSE)).thenReturn(null); Map<String, String> fieldMappings = ImmutableMap.of("NAME", "{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}name", "CONTENT", "{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}content"); // Call the method under test. rewriteFacetParametersComponent.rewriteMincountFacetFieldOption(fixed, mockParams, "facet.mincount", fieldMappings, mockRequest); // Check that the mincount is kept as 2 and the field name is converted to the format stored by Solr. String actualNameCount = fixed.get( "f.{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}name.facet.mincount"); assertEquals("Expected the mincount to be 2.", "2", actualNameCount); String actualContentCount = fixed.get( "f.{!afts key=SEARCH.FACET_FIELDS.LOCATION}text@s____@{http://www.alfresco.org/model/content/1.0}content.facet.mincount"); assertEquals("Expected the mincount to be 1.", "1", actualContentCount); }
From source file:org.alfresco.solr.component.RewriteFacetParametersComponentTest.java
License:Open Source License
@Test public void rewriteMincountFacetPivotOption_mincountMissing_shouldSetPivotMinCountToOne() { // There are no existing facet parameters. ModifiableSolrParams fixed = new ModifiableSolrParams(); when(mockParams.getParameterNamesIterator()).thenReturn(Iterators.empty()); when(mockParams.get(ShardParams.SHARDS_PURPOSE)).thenReturn(null); Map<String, String> fieldMappings = new HashMap<>(); // Call the method under test. rewriteFacetParametersComponent.rewriteMincountFacetFieldOption(fixed, mockParams, "facet.pivot.mincount", fieldMappings, mockRequest); // Check that the mincount is set to 1. String actual = fixed.get("facet.pivot.mincount"); assertEquals("Expected the existing mincount to be preserved.", "1", actual); }