lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject [1/2] lucene-solr:branch_7x: LUCENE-8379: add TermQuery.getTermStates
Date Thu, 05 Jul 2018 14:49:19 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x 607e81757 -> b9e064b93


LUCENE-8379: add TermQuery.getTermStates


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/51c89064
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/51c89064
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/51c89064

Branch: refs/heads/branch_7x
Commit: 51c890645dbfa6547d157da6a443e4c0ae5438f9
Parents: 607e817
Author: Mike McCandless <mikemccand@apache.org>
Authored: Thu Jul 5 10:16:55 2018 -0400
Committer: Mike McCandless <mikemccand@apache.org>
Committed: Thu Jul 5 10:17:40 2018 -0400

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |  2 ++
 .../org/apache/lucene/search/TermQuery.java     |  7 +++++
 .../org/apache/lucene/search/TestTermQuery.java | 30 ++++++++++++++++++++
 3 files changed, 39 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/51c89064/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 57f5f4c..19a868f 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -17,6 +17,8 @@ API Changes:
 * LUCENE-8378: Add DocIdSetIterator.range static method to return an iterator
   matching a range of docids (Mike McCandless)
 
+* LUCENE-8379: Add experimental TermQuery.getTermStates method (Mike McCandless)
+
 Bug Fixes:
 
 * LUCENE-8380: UTF8TaxonomyWriterCache inconsistency. (Ruslan Torobaev, Dawid Weiss)

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/51c89064/lucene/core/src/java/org/apache/lucene/search/TermQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/TermQuery.java b/lucene/core/src/java/org/apache/lucene/search/TermQuery.java
index af14ba4..d04206a 100644
--- a/lucene/core/src/java/org/apache/lucene/search/TermQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/TermQuery.java
@@ -234,6 +234,13 @@ public class TermQuery extends Query {
     return buffer.toString();
   }
 
+  /** Returns the {@link TermStates} passed to the constructor, or null if it was not passed.
+   *
+   * @lucene.experimental */
+  public TermStates getTermStates() {
+    return perReaderTermState;
+  }
+
   /** Returns true iff <code>o</code> is equal to this. */
   @Override
   public boolean equals(Object other) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/51c89064/lucene/core/src/test/org/apache/lucene/search/TestTermQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestTermQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestTermQuery.java
index 88e9e53..5c67412 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestTermQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestTermQuery.java
@@ -92,6 +92,36 @@ public class TestTermQuery extends LuceneTestCase {
     IOUtils.close(reader, w, dir);
   }
 
+  public void testGetTermStates() throws Exception {
+
+    // no term states:
+    assertNull(new TermQuery(new Term("foo", "bar")).getTermStates());
+
+    Directory dir = newDirectory();
+    RandomIndexWriter w = new RandomIndexWriter(random(), dir, newIndexWriterConfig().setMergePolicy(NoMergePolicy.INSTANCE));
+    // segment that contains the term
+    Document doc = new Document();
+    doc.add(new StringField("foo", "bar", Store.NO));
+    w.addDocument(doc);
+    w.getReader().close();
+    // segment that does not contain the term
+    doc = new Document();
+    doc.add(new StringField("foo", "baz", Store.NO));
+    w.addDocument(doc);
+    w.getReader().close();
+    // segment that does not contain the field
+    w.addDocument(new Document());
+
+    DirectoryReader reader = w.getReader();
+    FilterDirectoryReader noSeekReader = new NoSeekDirectoryReader(reader);
+    IndexSearcher noSeekSearcher = new IndexSearcher(noSeekReader);
+    Query query = new TermQuery(new Term("foo", "bar"));
+    TermQuery queryWithContext = new TermQuery(new Term("foo", "bar"),
+        TermStates.build(reader.getContext(), new Term("foo", "bar"), true));
+    assertNotNull(queryWithContext.getTermStates());
+    IOUtils.close(reader, w, dir);
+  }
+
   private static class NoSeekDirectoryReader extends FilterDirectoryReader {
 
     public NoSeekDirectoryReader(DirectoryReader in) throws IOException {


Mime
View raw message