Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that you index the <code>NUMBER_OF_ARGUMENTS</code> field as an <code>IntField</code>, but the version passed back from the index is a <code>StoredField</code>. When you reindex it, it is no longer formatted as an <code>IntField</code>, and so a <code>NumericRangeQuery</code> doesn't get any results. You can simply set the query term on <code>NUMBER_OF_ARGUMENTS</code> to an <code>Occur.SHOULD</code> clause, to see that the problem is on that field.</p> <p>One solution would be to manually re-add that field to the document, something like:</p> <pre><code>public static void main(String[] args) throws IOException, ParseException { IndexWriter luceneIndexWriter = new IndexWriter( FSDirectory.open(new File("/tmp/test")), createWriterConfig(64)); Document doc1 = createDocument(ID1, "context1", 1); luceneIndexWriter.addDocument(doc1); Document doc2 = createDocument(ID2, "context2", 2); luceneIndexWriter.addDocument(doc2); System.out.println("Found doc1: " + findDocument(ID1, 1, luceneIndexWriter)); System.out.println("Found doc2: " + findDocument(ID2, 2, luceneIndexWriter)); doc1 = findDocument(ID1, 1, luceneIndexWriter); // Section 1 doc1.removeField(CONTEXT_FIELD); doc1.add(new TextField(CONTEXT_FIELD, "context1_changed", Field.Store.YES)); //re-adding the IntField here Number num = doc1.getField(NUMBER_OF_ARGUMENTS).numericValue(); doc1.removeField(NUMBER_OF_ARGUMENTS); doc1.add(new IntField(NUMBER_OF_ARGUMENTS, num.intValue(), Field.Store.YES)); luceneIndexWriter.updateDocument(new Term(METHOD_NAME_FIELD, "text"), doc1); System.out.println("Found doc1: " + findDocument(ID1, 1, luceneIndexWriter)); System.out.println("Found doc2: " + findDocument(ID2, 2, luceneIndexWriter)); // Section 2 doc1 = findDocument(ID1, 1, luceneIndexWriter); doc1.removeField(CONTEXT_FIELD); doc1.add(new TextField(CONTEXT_FIELD, "context1_changed2", Field.Store.YES)); luceneIndexWriter.updateDocument(new Term(METHOD_NAME_FIELD, "text"), doc1); num = doc1.getField(NUMBER_OF_ARGUMENTS).numericValue(); doc1.removeField(NUMBER_OF_ARGUMENTS); doc1.add(new IntField(NUMBER_OF_ARGUMENTS, num.intValue(), Field.Store.YES)); luceneIndexWriter.updateDocument(new Term(METHOD_NAME_FIELD, "text"), doc1); System.out.println("Found doc1: " + findDocument(ID1, 1, luceneIndexWriter)); System.out.println("Found doc2: " + findDocument(ID2, 2, luceneIndexWriter)); luceneIndexWriter.close(); } </code></pre> <p>The safer approach is to build a new replacement document, rather than attempting to modify and persist the one pulled from the index. The stored version of the document retrieved from the index could certainly be lacking a number of pieces of information about how the field should be indexed.</p> <hr> <p>One sidenote, when creating a test function that builds a small index, I would use:</p> <pre><code>config.setOpenMode(OpenMode.CREATE); </code></pre> <p>rather than <code>CREATE_OR_APPEND</code>. This allows you to start with an empty index, so results are more readily predictable, and you can view the contents of the index as you build it fresh each time, for debugging, like:</p> <pre><code>public static void outputTheWholeThing(IndexWriter writer) throws IOException { DirectoryReader reader = DirectoryReader.open(writer, true); for (int i=0; i&lt;reader.maxDoc(); i++) { Document doc = reader.document(i); System.out.println(doc); } System.out.println("Pending deletions:" + reader.numDeletedDocs()); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload