Additionally (and I haven't been in low-level Lucene for a LONG time so caveat emptor), in general ID types should not be tokenized. I'd model my field definition after the Lucene StringField class. It looks like you can avoid defining a FieldType altogether and just use StringField.TYPE_STORED for your iDoc.add call....
FWIW, Erick On Sat, Jun 20, 2015 at 8:48 AM, Đạt Cao Mạnh <caomanhdat...@gmail.com> wrote: > You can check following possibilities : > - doc.id.toString() return same string for all of your documents. > - your tokenstream for doc.id.toString() return same token for all of your > documents. Ex: id "1 23" -> {"1","23"}. id "1 56" -> {"1","56"}. So when > you delete document by using iw.deleteDocuments(new Term("id", "1")) it > will delete both documents. > > On Sat, Jun 20, 2015 at 4:44 PM, Behnam Khoshsafar <b.khoshsa...@hamgam.ir> > wrote: > >> I'm using Lucene 5.1.0 to index a document and search it. I have a lot of >> documents, over 1000000, which are stored in a database. When I start >> running the project for the first time, I use Lucene to index these >> documents. Now I want to delete one document from the database and indexes. >> I also choose an id for each index. I am using the following command to >> delete, but it's delete all index. >> >> iw.deleteDocuments(new Term("id", doc.id)); >> Also, I used a Query to delete but it will delete all index. >> >> I add documents to the index as follows: >> >> iDoc = new org.apache.lucene.document.Document(); >> FieldType fieldType = new FieldType(); >> fieldType.setIndexOptions( >> IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS); >> fieldType.setTokenized(true); >> fieldType.setStored(true); >> fieldType.setOmitNorms(true); >> fieldType.setStoreTermVectors(true); >> fieldType.setStoreTermVectorOffsets(true); >> fieldType.setStoreTermVectorPayloads(true); >> fieldType.setStoreTermVectorPositions(true); >> iDoc.add(new Field("id", doc.id.toString(), fieldType)); >> iw.addDocument(iDoc); >> > > > > > -- > *Best regards,* > *Cao Mạnh Đạt* > > > > > > > *D.O.B : 31-07-1991Cell: (+84) 946.328.329E-mail: caomanhdat...@gmail.com > <caomanhdat...@gmail.com>Hanoi University of Science and TechnologySchool > of information & communication technologyClass : Computer Science K54* --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org