Apache Lucene open-source search software
SOLR-1188: Minor efficiency improvement in TermVectorComponent
Grant Ingersolleb51d48e8202
diff --git a/CHANGES.txt b/CHANGES.txtindex ab796da63f2..c996c30cecc 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -269,10 +269,6 @@ Optimizations12. SOLR-1165: Use Lucene Filters and pass them down to the Lucenesearch methods to filter earlier and improve performance. (yonik)-13. SOLR-1111: Use per-segment sorting to share fieldcache elements- across unchanged segments. This saves memory and reduces- commit times for incremental updates to the index. (yonik)-Bug Fixes----------------------diff --git a/src/java/org/apache/solr/handler/component/TermVectorComponent.java b/src/java/org/apache/solr/handler/component/TermVectorComponent.javaindex 792cb5b9878..73f5f74b729 100644--- a/src/java/org/apache/solr/handler/component/TermVectorComponent.java+++ b/src/java/org/apache/solr/handler/component/TermVectorComponent.java@@ -193,6 +193,16 @@ public class TermVectorComponent extends SearchComponent implements SolrCoreAwarprivate NamedList fieldNL;private Term currentTerm;+ /**+ *+ * @param fields+ * @param reader+ * @param termFreq+ * @param positions true if the TVM should try to get position info from the Term Vector, assuming it is present+ * @param offsets true if the TVM should try to get offset info from the Term Vector, assuming it is present+ * @param docFreq+ * @param tfIdf+ */public TVMapper(String[] fields, IndexReader reader, boolean termFreq, boolean positions, boolean offsets, boolean docFreq, boolean tfIdf) {this.reader = reader;@@ -268,6 +278,16 @@ public class TermVectorComponent extends SearchComponent implements SolrCoreAwarfieldNL = null;}}++ @Override+ public boolean isIgnoringPositions() {+ return this.positions == false; // if we are not interested in positions, then return true telling Lucene to skip loading them+ }++ @Override+ public boolean isIgnoringOffsets() {+ return this.offsets == false; // if we are not interested in offsets, then return true telling Lucene to skip loading them+ }}public void prepare(ResponseBuilder rb) throws IOException {diff --git a/src/test/org/apache/solr/handler/component/TermVectorComponentTest.java b/src/test/org/apache/solr/handler/component/TermVectorComponentTest.javaindex 710b29ddfe0..2fbcfab297b 100644--- a/src/test/org/apache/solr/handler/component/TermVectorComponentTest.java+++ b/src/test/org/apache/solr/handler/component/TermVectorComponentTest.java@@ -93,7 +93,11 @@ public class TermVectorComponentTest extends AbstractSolrTestCase {NamedList titl = (NamedList) field.get("titl");assertTrue("titl is null and it shouldn't be", titl != null);assertTrue(titl.get("tf") + " does not equal: " + 2, ((Integer) titl.get("tf")) == 2);-+ //there should not be any positions or offsets+ NamedList positions = (NamedList) titl.get("positions");+ assertTrue("positions is not null and it should be", positions == null);+ NamedList offsets = (NamedList) titl.get("offsets");+ assertTrue("offsets is not null and it should be", offsets == null);String uniqueKeyFieldName = (String) termVectors.getVal(1);assertTrue("uniqueKeyFieldName is null and it shouldn't be", uniqueKeyFieldName != null);assertTrue(uniqueKeyFieldName + " is not equal to " + "id", uniqueKeyFieldName.equals("id") == true);@@ -126,6 +130,24 @@ public class TermVectorComponentTest extends AbstractSolrTestCase {NamedList doc = (NamedList) termVectors.getVal(0);assertTrue("doc is null and it shouldn't be", doc != null);assertTrue(doc.size() + " does not equal: " + 2, doc.size() == 2);+ NamedList offtv = (NamedList) doc.get("test_posofftv");+ assertTrue("offtv is null and it shouldn't be", offtv != null);+ assertTrue("offtv Size: " + offtv.size() + " is not: " + 2, offtv.size() == 2);+ NamedList another = (NamedList) offtv.get("anoth");+ NamedList offsets = (NamedList) another.get("offsets");+ assertTrue("offsets is null and it shouldn't be", offsets != null);+ assertTrue("offsets Size: " + offsets.size() + " is not greater than: " + 0, offsets.size() > 0);+ NamedList pos = (NamedList) another.get("positions");+ assertTrue("pos is null and it shouldn't be", pos != null);+ assertTrue("pos Size: " + pos.size() + " is not greater than: " + 0, pos.size() > 0);+ Integer df = (Integer) another.get("df");+ assertTrue("df is null and it shouldn't be", df != null);+ assertTrue(df + " does not equal: " + 2, df == 2);+ Double tfIdf = (Double) another.get("tf-idf");+ assertTrue("tfIdf is null and it shouldn't be", tfIdf != null);+ assertTrue(tfIdf + " does not equal: " + 0.5, tfIdf == 0.5);++}