Skip to content
This repository has been archived by the owner on Nov 22, 2017. It is now read-only.

delete doesn't always delete #12

Closed
kwiggen opened this issue Apr 28, 2010 · 3 comments
Closed

delete doesn't always delete #12

kwiggen opened this issue Apr 28, 2010 · 3 comments

Comments

@kwiggen
Copy link

kwiggen commented Apr 28, 2010

If I change the testDelete unit test to:

public void testDelete() throws Exception {

    IndexReader indexReader = new IndexReader(indexName, client);
    IndexSearcher searcher = new IndexSearcher(indexReader);

    QueryParser qp = new QueryParser(Version.LUCENE_30, "key", analyzer);
    Query q = qp.parse("+key:\u5639\u563b");

    TopDocs docs = searcher.search(q, 10);

    assertEquals(1, docs.totalHits);


    indexWriter.deleteDocuments(new Term("key",new String("\u5639\u563b")));

    QueryParser qp2 = new QueryParser(Version.LUCENE_30, "key", analyzer);
    Query q2 = qp2.parse("+key:\u5639\u563b");

    TopDocs docs2 = searcher.search(q2, 10);

    ScoreDoc scoreDoc = docs.scoreDocs[0];   
    Document doc = searcher.doc(scoreDoc.doc);

    assertEquals(0, doc.getFields().size());

    assertEquals(0, docs2.totalHits);
}

I get the unittest to fail. I have not honestly looked at the details (hopefully I will have time in a few days), however I can guess that this is due to the fact that Cassandra is not deleting the KEY underneath (but I can be completely wrong). Note that the Document that is returned has no Fields to it. I would think that these should be removed from the list of items returned in TopDocs.

Also possible I don't understand something basic in Lucene itself.

@kwiggen
Copy link
Author

kwiggen commented Apr 28, 2010

OK this seems to be my misunderstanding. With a file system backed lucene I think you need to close a writer, before a reader can see the changes.

If I add

indexWriter.commit();

to the code it does nothing, however

indexReader.clearCache();

does the trick.

What is the lifespan of a Reader and Writer in the Cassandra world? Should I be getting a new Reader/Writer for each user interaction?

Sorry for the noob questions, I am off to read more...

@tjake
Copy link
Owner

tjake commented Apr 29, 2010

Reader should be reopened whenever you want to see changes. this does nothing more then clear its internal cache.

@kwiggen
Copy link
Author

kwiggen commented Apr 29, 2010

But the 2nd read in my example gives you a TopDocs size of 1, but when you get the Document it has no Field objects. I would consider this a bug as you get reference to the Document, but it is empty. Either the Document should be filled in, or not returned.

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants