Have been struggling for this two days now, just can\'t delete the document with indexWriter.deleteDocuments(term)
Here I will put the code which will do a
Your problem is in the analyzer. SimpleAnalyzer
defines tokens as maximal strings of letters (StandardAnalyzer
, or even WhitespaceAnalyzer
, are more typical choices), so the value you are indexing gets split into the tokens: "b", "a", "b", "d", "f". The delete method you've defined doesn't pass through the analyzer though, but rather just creates a raw term. You can see this in action if you try replacing your main
with this:
generateIndex("5836962b0293a47b09d345f1");
query("5836962b0293a47b09d345f1");
delete("b");
query("5836962b0293a47b09d345f1");
As a general rule, queries and terms and such do not analyze, QueryParser does.
For (what looks like) an identifier field, you probably don't really want to analyze this field at all. In that case, add this to the FieldType:
fieldType.setTokenized(false);
You will then have to change your query (again, QueryParser analyzes), and use TermQuery
instead.
Query query = new TermQuery(new Term("_id", id));