Apache Solr open-source search software
fix RandomFacetSource (benchmark) random picking logic and move to a list of CategoryPath
Shai Ererad9e016c4d0a2
diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/FacetSource.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/FacetSource.javaindex 95c90ce845d..34b2361e028 100644--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/FacetSource.java+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/FacetSource.java@@ -18,8 +18,9 @@ package org.apache.lucene.benchmark.byTask.feeds;*/import java.io.IOException;+import java.util.List;-import org.apache.lucene.facet.associations.CategoryAssociationsContainer;+import org.apache.lucene.facet.taxonomy.CategoryPath;/*** Source items for facets.@@ -29,12 +30,11 @@ import org.apache.lucene.facet.associations.CategoryAssociationsContainer;public abstract class FacetSource extends ContentItemsSource {/**- * Returns the next {@link CategoryAssociationsContainer facets content item}.- * Implementations must account for multi-threading, as multiple threads can- * call this method simultaneously.+ * Fills the next facets content items in the given list. Implementations must+ * account for multi-threading, as multiple threads can call this method+ * simultaneously.*/- public abstract CategoryAssociationsContainer getNextFacets(CategoryAssociationsContainer facets)- throws NoMoreDataException, IOException;+ public abstract void getNextFacets(List<CategoryPath> facets) throws NoMoreDataException, IOException;@Overridepublic void resetInputs() throws IOException {diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/RandomFacetSource.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/RandomFacetSource.javaindex bc24bd6b7f9..99d5f210db8 100644--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/RandomFacetSource.java+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/RandomFacetSource.java@@ -18,10 +18,10 @@ package org.apache.lucene.benchmark.byTask.feeds;*/import java.io.IOException;+import java.util.List;import java.util.Random;import org.apache.lucene.benchmark.byTask.utils.Config;-import org.apache.lucene.facet.associations.CategoryAssociationsContainer;import org.apache.lucene.facet.taxonomy.CategoryPath;/**@@ -29,42 +29,38 @@ import org.apache.lucene.facet.taxonomy.CategoryPath;* <p>* Supports the following parameters:* <ul>- * <li><b>rand.seed</b> - defines the seed to initialize Random with (default: <b>13</b>).+ * <li><b>rand.seed</b> - defines the seed to initialize {@link Random} with+ * (default: <b>13</b>).* <li><b>max.doc.facets</b> - maximal #facets per doc (default: <b>10</b>).- * Actual number of facets in a certain doc would be anything between 1 and that number.- * <li><b>max.facet.depth</b> - maximal #components in a facet (default: <b>3</b>).- * Actual number of components in a certain facet would be anything between 1 and that number.+ * Actual number of facets in a certain doc would be anything between 1 and that+ * number.+ * <li><b>max.facet.depth</b> - maximal #components in a facet (default:+ * <b>3</b>). Actual number of components in a certain facet would be anything+ * between 1 and that number.* </ul>*/public class RandomFacetSource extends FacetSource {- Random random;-- private int maxDocFacets = 10;- private int maxFacetDepth = 3;+ private Random random;+ private int maxDocFacets;+ private int maxFacetDepth;private int maxValue = maxDocFacets * maxFacetDepth;@Override- public CategoryAssociationsContainer getNextFacets(CategoryAssociationsContainer facets)- throws NoMoreDataException, IOException {- if (facets == null) {- facets = new CategoryAssociationsContainer();- } else {- facets.clear();- }- int numFacets = 1 + random.nextInt(maxDocFacets-1); // at least one facet to each doc+ public void getNextFacets(List<CategoryPath> facets) throws NoMoreDataException, IOException {+ facets.clear();+ int numFacets = 1 + random.nextInt(maxDocFacets); // at least one facet to each docfor (int i = 0; i < numFacets; i++) {- int depth = 1 + random.nextInt(maxFacetDepth - 1); // depth 0 is not useful+ int depth = 1 + random.nextInt(maxFacetDepth); // depth 0 is not usefulString[] components = new String[depth];for (int k = 0; k < depth; k++) {components[k] = Integer.toString(random.nextInt(maxValue));addItem();}CategoryPath cp = new CategoryPath(components);- facets.setAssociation(cp, null);+ facets.add(cp);addBytes(cp.toString().length()); // very rough approximation}- return facets;}@Override@@ -76,8 +72,8 @@ public class RandomFacetSource extends FacetSource {public void setConfig(Config config) {super.setConfig(config);random = new Random(config.get("rand.seed", 13));- maxDocFacets = config.get("max.doc.facets", 200);- maxFacetDepth = config.get("max.facet.depth", 10);+ maxDocFacets = config.get("max.doc.facets", 10);+ maxFacetDepth = config.get("max.facet.depth", 3);maxValue = maxDocFacets * maxFacetDepth;}}diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/AddFacetedDocTask.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/AddFacetedDocTask.javaindex 55c880f0b40..9fa660aaf31 100644--- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/AddFacetedDocTask.java+++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/AddFacetedDocTask.java@@ -17,49 +17,56 @@ package org.apache.lucene.benchmark.byTask.tasks;* limitations under the License.*/+import java.util.ArrayList;+import java.util.List;+import org.apache.lucene.benchmark.byTask.PerfRunData;import org.apache.lucene.benchmark.byTask.feeds.FacetSource;-import org.apache.lucene.facet.associations.CategoryAssociationsContainer;import org.apache.lucene.facet.index.FacetFields;+import org.apache.lucene.facet.taxonomy.CategoryPath;/*** Add a faceted document.* <p>* Config properties:* <ul>- * <li><b>with.facets</b>=<tells whether to actually add any facets to the document| Default: true>- * <br>This config property allows to easily compare the performance of adding docs with and without facets.- * Note that facets are created even when this is false, just that they are not added to the document (nor to the taxonomy).- * </ul>+ * <li><b>with.facets</b>=<tells whether to actually add any facets to the+ * document| Default: true> <br>+ * This config property allows to easily compare the performance of adding docs+ * with and without facets. Note that facets are created even when this is+ * false, just that they are not added to the document (nor to the taxonomy).+ * </ul>* <p>* See {@link AddDocTask} for general document parameters and configuration.* <p>- * Makes use of the {@link FacetSource} in effect - see {@link PerfRunData} for facet source settings.+ * Makes use of the {@link FacetSource} in effect - see {@link PerfRunData} for+ * facet source settings.*/public class AddFacetedDocTask extends AddDocTask {+ private final List<CategoryPath> facets = new ArrayList<CategoryPath>();+ private FacetFields facetFields;+public AddFacetedDocTask(PerfRunData runData) {super(runData);}- private CategoryAssociationsContainer facets = null;- private FacetFields facetFields = null;- private boolean withFacets = true;-@Overridepublic void setup() throws Exception {super.setup();- // create the facets even if they should not be added - allows to measure the effect of just adding facets- facets = getRunData().getFacetSource().getNextFacets(facets);- withFacets = getRunData().getConfig().get("with.facets", true);- if (withFacets) {- facetFields = new FacetFields(getRunData().getTaxonomyWriter());+ if (facetFields == null) {+ boolean withFacets = getRunData().getConfig().get("with.facets", true);+ if (withFacets) {+ FacetSource facetsSource = getRunData().getFacetSource();+ facetFields = withFacets ? new FacetFields(getRunData().getTaxonomyWriter()) : null;+ facetsSource.getNextFacets(facets);+ }}}@Overrideprotected String getLogMessage(int recsCount) {- if (!withFacets) {+ if (facetFields == null) {return super.getLogMessage(recsCount);}return super.getLogMessage(recsCount)+ " with facets";@@ -67,7 +74,7 @@ public class AddFacetedDocTask extends AddDocTask {@Overridepublic int doLogic() throws Exception {- if (withFacets) {+ if (facetFields != null) {facetFields.addFields(doc, facets);}return super.doLogic();