X-Git-Url: https://git.mdrn.pl/pylucene.git/blobdiff_plain/a2e61f0c04805cfcb8706176758d1283c7e3a55c..aaeed5504b982cf3545252ab528713250aa33eed:/lucene-java-3.4.0/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetVectorHighlightTask.java diff --git a/lucene-java-3.4.0/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetVectorHighlightTask.java b/lucene-java-3.4.0/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetVectorHighlightTask.java deleted file mode 100644 index 1fec3de..0000000 --- a/lucene-java-3.4.0/lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/tasks/SearchTravRetVectorHighlightTask.java +++ /dev/null @@ -1,145 +0,0 @@ -package org.apache.lucene.benchmark.byTask.tasks; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.lucene.analysis.Analyzer; -import org.apache.lucene.benchmark.byTask.PerfRunData; -import org.apache.lucene.document.Document; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.vectorhighlight.FastVectorHighlighter; -import org.apache.lucene.search.vectorhighlight.FieldQuery; - -import java.util.Set; -import java.util.Collection; -import java.util.HashSet; -import java.util.Collections; - -/** - * Search and Traverse and Retrieve docs task. Highlight the fields in the retrieved documents by using FastVectorHighlighter. - * - *

Note: This task reuses the reader if it is already open. - * Otherwise a reader is opened at start and closed at the end. - *

- * - *

Takes optional multivalued, comma separated param string as: size[<traversal size>],highlight[<int>],maxFrags[<int>],mergeContiguous[<boolean>],fields[name1;name2;...]

- * - * Example: - *
"SearchVecHlgtSameRdr" SearchTravRetVectorHighlight(size[10],highlight[10],maxFrags[3],fields[body]) > : 1000
- * 
- * - * Fields must be stored and term vector offsets and positions in order must be true for this task to work. - * - *

Other side effects: counts additional 1 (record) for each traversed hit, - * and 1 more for each retrieved (non null) document and 1 for each fragment returned.

- */ -public class SearchTravRetVectorHighlightTask extends SearchTravTask { - - protected int numToHighlight = Integer.MAX_VALUE; - protected int maxFrags = 2; - protected int fragSize = 100; - protected Set paramFields = Collections.emptySet(); - protected FastVectorHighlighter highlighter; - - public SearchTravRetVectorHighlightTask(PerfRunData runData) { - super(runData); - } - - @Override - public void setup() throws Exception { - super.setup(); - //check to make sure either the doc is being stored - PerfRunData data = getRunData(); - if (data.getConfig().get("doc.stored", false) == false){ - throw new Exception("doc.stored must be set to true"); - } - if (data.getConfig().get("doc.term.vector.offsets", false) == false){ - throw new Exception("doc.term.vector.offsets must be set to true"); - } - if (data.getConfig().get("doc.term.vector.positions", false) == false){ - throw new Exception("doc.term.vector.positions must be set to true"); - } - } - - @Override - public boolean withRetrieve() { - return true; - } - - @Override - public int numToHighlight() { - return numToHighlight; - } - - @Override - protected BenchmarkHighlighter getBenchmarkHighlighter(Query q){ - highlighter = new FastVectorHighlighter( false, false ); - final FieldQuery fq = highlighter.getFieldQuery( q ); - return new BenchmarkHighlighter(){ - @Override - public int doHighlight(IndexReader reader, int doc, String field, - Document document, Analyzer analyzer, String text) throws Exception { - String[] fragments = highlighter.getBestFragments(fq, reader, doc, field, fragSize, maxFrags); - return fragments != null ? fragments.length : 0; - } - }; - } - - @Override - protected Collection getFieldsToHighlight(Document document) { - Collection result = super.getFieldsToHighlight(document); - //if stored is false, then result will be empty, in which case just get all the param fields - if (paramFields.isEmpty() == false && result.isEmpty() == false) { - result.retainAll(paramFields); - } else { - result = paramFields; - } - return result; - } - - @Override - public void setParams(String params) { - super.setParams(params); - String [] splits = params.split(","); - for (int i = 0; i < splits.length; i++) { - if (splits[i].startsWith("size[") == true){ - traversalSize = (int)Float.parseFloat(splits[i].substring("size[".length(),splits[i].length() - 1)); - } else if (splits[i].startsWith("highlight[") == true){ - numToHighlight = (int)Float.parseFloat(splits[i].substring("highlight[".length(),splits[i].length() - 1)); - } else if (splits[i].startsWith("maxFrags[") == true){ - maxFrags = (int)Float.parseFloat(splits[i].substring("maxFrags[".length(),splits[i].length() - 1)); - } else if (splits[i].startsWith("fragSize[") == true){ - fragSize = (int)Float.parseFloat(splits[i].substring("fragSize[".length(),splits[i].length() - 1)); - } else if (splits[i].startsWith("fields[") == true){ - paramFields = new HashSet(); - String fieldNames = splits[i].substring("fields[".length(), splits[i].length() - 1); - String [] fieldSplits = fieldNames.split(";"); - for (int j = 0; j < fieldSplits.length; j++) { - paramFields.add(fieldSplits[j]); - } - - } - } - } -}