fix RandomFacetSource (benchmark) random picking logic and move to a list of CategoryPath

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1436206 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2013-01-21 06:58:40 +00:00
parent 4be9caa5b2
commit d9e016c4d0
3 changed files with 48 additions and 45 deletions

View File

@ -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;
@Override
public void resetInputs() throws IOException {

View File

@ -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 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 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;
}
}

View File

@ -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>=&lt;tells whether to actually add any facets to the document| Default: true&gt;
* <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>=&lt;tells whether to actually add any facets to the
* document| Default: true&gt; <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 AddDocTask {
@Override
public int doLogic() throws Exception {
if (withFacets) {
if (facetFields != null) {
facetFields.addFields(doc, facets);
}
return super.doLogic();