FacetsCollector.search(searcher, query, null,1, Sort.INDEXORDER, facetsCollector); switch (secureFacetConfiguration.getMode()) { case INSECURE: facets = new SortedSetDocValuesFacetCounts(state, facetsCollector);
hitCount += matchingDocs.totalHits; int sampleSize = secureFacetConfiguration.getStatisticalFacetSampleSize(); long randomSeed = secureFacetConfiguration.getRandomSeed();
this.secureFacets = SecureFacetConfiguration.getInstance(randomSeed, facetsConfig); this.numberOfTopFacets = getOptionalValue(facetsConfig, PROP_FACETS_TOP_CHILDREN, DEFAULT_FACET_COUNT); } else { this.secureFacets = SecureFacetConfiguration.getInstance(randomSeed, null); this.numberOfTopFacets = DEFAULT_FACET_COUNT;
FacetsCollector.search(searcher, query, null,1, Sort.INDEXORDER, facetsCollector); switch (secureFacetConfiguration.getMode()) { case INSECURE: facets = new SortedSetDocValuesFacetCounts(state, facetsCollector);
hitCount += matchingDocs.totalHits; int sampleSize = secureFacetConfiguration.getStatisticalFacetSampleSize(); long randomSeed = secureFacetConfiguration.getRandomSeed();
@Test public void orderingOfOverrides() { System.setProperty(PROP_SECURE_FACETS_VALUE_JVM_PARAM, "insecure"); System.setProperty(STATISTICAL_FACET_SAMPLE_SIZE_JVM_PARAM, "10"); NodeState nodeState; SecureFacetConfiguration config; int sampleSize; nodeState = builder.child("config1").setProperty(PROP_SECURE_FACETS, "secure").getNodeState(); config = SecureFacetConfiguration.getInstance(RANDOM_SEED, nodeState); assertEquals(MODE.SECURE, config.getMode()); assertEquals(-1, config.getStatisticalFacetSampleSize()); nodeState = builder.child("config2") .setProperty(PROP_SECURE_FACETS, PROP_SECURE_FACETS_VALUE_STATISTICAL) .setProperty(PROP_STATISTICAL_FACET_SAMPLE_SIZE, 20) .getNodeState(); config = SecureFacetConfiguration.getInstance(RANDOM_SEED, nodeState); sampleSize = config.getStatisticalFacetSampleSize(); assertEquals(20, sampleSize); nodeState = builder.child("config3") .setProperty(PROP_SECURE_FACETS, PROP_SECURE_FACETS_VALUE_STATISTICAL) .getNodeState(); config = SecureFacetConfiguration.getInstance(RANDOM_SEED, nodeState); sampleSize = config.getStatisticalFacetSampleSize(); assertEquals(10, sampleSize); }
@Test public void invalidSecureFacetSampleSize() { int sampleSize; NodeBuilder configBuilder = builder.child("config").setProperty(PROP_SECURE_FACETS, PROP_SECURE_FACETS_VALUE_STATISTICAL); NodeState nodeState = configBuilder.getNodeState(); configBuilder.setProperty(PROP_STATISTICAL_FACET_SAMPLE_SIZE, -10); sampleSize = SecureFacetConfiguration.getInstance(RANDOM_SEED, nodeState).getStatisticalFacetSampleSize(); assertEquals(STATISTICAL_FACET_SAMPLE_SIZE_DEFAULT, sampleSize); System.setProperty(STATISTICAL_FACET_SAMPLE_SIZE_JVM_PARAM, "10"); configBuilder.setProperty(PROP_STATISTICAL_FACET_SAMPLE_SIZE, -20); nodeState = configBuilder.getNodeState(); sampleSize = SecureFacetConfiguration.getInstance(RANDOM_SEED, nodeState).getStatisticalFacetSampleSize(); assertEquals(10, sampleSize); System.setProperty(STATISTICAL_FACET_SAMPLE_SIZE_JVM_PARAM, "-10"); configBuilder.setProperty(PROP_STATISTICAL_FACET_SAMPLE_SIZE, -20); sampleSize = SecureFacetConfiguration.getInstance(RANDOM_SEED, nodeState).getStatisticalFacetSampleSize(); assertEquals(STATISTICAL_FACET_SAMPLE_SIZE_DEFAULT, sampleSize); System.setProperty(STATISTICAL_FACET_SAMPLE_SIZE_JVM_PARAM, "-10"); configBuilder.setProperty(PROP_STATISTICAL_FACET_SAMPLE_SIZE, 10); nodeState = configBuilder.getNodeState(); sampleSize = SecureFacetConfiguration.getInstance(RANDOM_SEED, nodeState).getStatisticalFacetSampleSize(); assertEquals(10, sampleSize); }
@Test public void systemPropSecureFacet() { SecureFacetConfiguration config; System.setProperty(PROP_SECURE_FACETS_VALUE_JVM_PARAM, "random"); config = SecureFacetConfiguration.getInstance(RANDOM_SEED, root); assertEquals(MODE.SECURE, config.getMode()); System.setProperty(PROP_SECURE_FACETS_VALUE_JVM_PARAM, "secure"); config = SecureFacetConfiguration.getInstance(RANDOM_SEED, root); assertEquals(MODE.SECURE, config.getMode()); System.setProperty(PROP_SECURE_FACETS_VALUE_JVM_PARAM, "insecure"); config = SecureFacetConfiguration.getInstance(RANDOM_SEED, root); assertEquals(MODE.INSECURE, config.getMode()); System.setProperty(PROP_SECURE_FACETS_VALUE_JVM_PARAM, "insecure"); builder.setProperty(PROP_SECURE_FACETS, "secure"); config = SecureFacetConfiguration.getInstance(RANDOM_SEED, builder.getNodeState()); assertEquals(MODE.SECURE, config.getMode()); }
@Test public void systemPropSecureFacetStatisticalSampleSize() { int sampleSize; System.setProperty(PROP_SECURE_FACETS_VALUE_JVM_PARAM, PROP_SECURE_FACETS_VALUE_STATISTICAL); System.setProperty(STATISTICAL_FACET_SAMPLE_SIZE_JVM_PARAM, "10"); sampleSize = SecureFacetConfiguration.getInstance(RANDOM_SEED, root).getStatisticalFacetSampleSize(); assertEquals(10, sampleSize); System.setProperty(STATISTICAL_FACET_SAMPLE_SIZE_JVM_PARAM, "-10"); sampleSize = SecureFacetConfiguration.getInstance(RANDOM_SEED, root).getStatisticalFacetSampleSize(); assertEquals(STATISTICAL_FACET_SAMPLE_SIZE_DEFAULT, sampleSize); System.setProperty(STATISTICAL_FACET_SAMPLE_SIZE_JVM_PARAM, "100000000000"); sampleSize = SecureFacetConfiguration.getInstance(RANDOM_SEED, root).getStatisticalFacetSampleSize(); assertEquals(STATISTICAL_FACET_SAMPLE_SIZE_DEFAULT, sampleSize); }
@Test public void randomSeedWithoutOneInDef() { long seed1 = new IndexDefinition(root, root, "/foo").getSecureFacetConfiguration().getRandomSeed(); long seed2 = new IndexDefinition(root, root, "/foo").getSecureFacetConfiguration().getRandomSeed(); assertNotEquals(seed1, seed2); } }
@Test public void legacyConfig() { NodeState ns = builder.setProperty(PROP_SECURE_FACETS, true).getNodeState(); SecureFacetConfiguration config = SecureFacetConfiguration.getInstance(RANDOM_SEED, ns); assertEquals(MODE.SECURE, config.getMode()); assertEquals(-1, config.getStatisticalFacetSampleSize()); ns = builder.setProperty(PROP_SECURE_FACETS, false).getNodeState(); config = SecureFacetConfiguration.getInstance(RANDOM_SEED, ns); assertEquals(MODE.INSECURE, config.getMode()); assertEquals(-1, config.getStatisticalFacetSampleSize()); }
static SecureFacetConfiguration getInstance(long randomSeed, NodeState facetConfigRoot) { if (facetConfigRoot == null) { facetConfigRoot = EMPTY_NODE; } MODE mode = getMode(facetConfigRoot); int statisticalFacetSampleSize; if (mode == MODE.STATISTICAL) { statisticalFacetSampleSize = getStatisticalFacetSampleSize(facetConfigRoot); } else { statisticalFacetSampleSize = -1; } return new SecureFacetConfiguration(randomSeed, mode, statisticalFacetSampleSize); }
@Test public void absentFacetConfigNode() { IndexDefinition idxDefn = new IndexDefinition(root, root, "/foo"); SecureFacetConfiguration config = idxDefn.getSecureFacetConfiguration(); assertEquals(MODE.SECURE, config.getMode()); }
@Test public void randomSeed() { long seed = new Random().nextLong(); builder.setProperty(PROP_RANDOM_SEED, seed); root = builder.getNodeState(); IndexDefinition idxDefn = new IndexDefinition(root, root, "/foo"); SecureFacetConfiguration config = idxDefn.getSecureFacetConfiguration(); assertEquals(seed, config.getRandomSeed()); }
@Test public void nonSecureConfigMode() { SecureFacetConfiguration config; builder.setProperty(PROP_SECURE_FACETS, "insecure"); config = SecureFacetConfiguration.getInstance(RANDOM_SEED, builder.getNodeState()); assertEquals(-1, config.getStatisticalFacetSampleSize()); builder.setProperty(PROP_SECURE_FACETS, "statistical"); config = SecureFacetConfiguration.getInstance(RANDOM_SEED, builder.getNodeState()); assertEquals(STATISTICAL_FACET_SAMPLE_SIZE_DEFAULT, config.getStatisticalFacetSampleSize()); }
@Test public void defaultConfig() { SecureFacetConfiguration config = SecureFacetConfiguration.getInstance(RANDOM_SEED, root); assertEquals(config.getMode(), MODE.SECURE); int sampleSize = config.getStatisticalFacetSampleSize(); assertEquals(-1, sampleSize); }