You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2013/01/21 07:58:41 UTC
svn commit: r1436206 - in
/lucene/dev/trunk/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask:
feeds/FacetSource.java feeds/RandomFacetSource.java
tasks/AddFacetedDocTask.java
Author: shaie
Date: Mon Jan 21 06:58:40 2013
New Revision: 1436206
URL: http://svn.apache.org/viewvc?rev=1436206&view=rev
Log:
fix RandomFacetSource (benchmark) random picking logic and move to a list of CategoryPath
Modified:
lucene/dev/trunk/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/FacetSource.java
lucene/dev/trunk/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/RandomFacetSource.java
lucene/dev/trunk/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/AddFacetedDocTask.java
Modified: lucene/dev/trunk/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/FacetSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/FacetSource.java?rev=1436206&r1=1436205&r2=1436206&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/FacetSource.java (original)
+++ lucene/dev/trunk/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/FacetSource.java Mon Jan 21 06:58:40 2013
@@ -18,8 +18,9 @@ package org.apache.lucene.benchmark.byTa
*/
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.associati
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;
@Override
public void resetInputs() throws IOException {
Modified: lucene/dev/trunk/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/RandomFacetSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/RandomFacetSource.java?rev=1436206&r1=1436205&r2=1436206&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/RandomFacetSource.java (original)
+++ lucene/dev/trunk/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/RandomFacetSource.java Mon Jan 21 06:58:40 2013
@@ -18,10 +18,10 @@ package org.apache.lucene.benchmark.byTa
*/
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.
* <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 doc
for (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 useful
String[] 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 F
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;
}
}
Modified: lucene/dev/trunk/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/AddFacetedDocTask.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/AddFacetedDocTask.java?rev=1436206&r1=1436205&r2=1436206&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/AddFacetedDocTask.java (original)
+++ lucene/dev/trunk/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/AddFacetedDocTask.java Mon Jan 21 06:58:40 2013
@@ -17,49 +17,56 @@ package org.apache.lucene.benchmark.byTa
* 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;
-
@Override
public 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);
+ }
}
}
@Override
protected 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 A
@Override
public int doLogic() throws Exception {
- if (withFacets) {
+ if (facetFields != null) {
facetFields.addFields(doc, facets);
}
return super.doLogic();