lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bushman, Lamont" <bus08...@byui.edu>
Subject Discrepancies between search results and reader.document(i).get("path")
Date Fri, 29 Mar 2013 09:23:21 GMT
I am getting a really weird problem. I am getting a discrepancy between what my search results
are the
files that are listed in my index, through their docId's

These are the files that the index says it has
------------------------------------
File: admin/hello.txt
File: admin/change.txt
File: admin/hello.txt~

Here I search for the word back, and I get admin/file.txt
-------------------------------------------------------------------------
Searching for: back
1 total matching documents
admin/file.txt
I am <B>back</B>.

My last change was to remove hello.txt~  and add file.txt.  The search results reflect that
change.
Yet, the listing of the files that I get through the following procedure:
               reader.numDocs();
               for (0 to numDocs)
                   reader.document(i).get("path");
gives me the above listing of files.



Following are the essential parts of my code, thanks for any help.



This snippet of one of my classes looks at all of my documents and displays their file path.
------------------------------------------------------------------------------------------------
Directory dir = FSDirectory.open(mIndexFolder);
IndexReader reader = DirectoryReader.open(dir);
int numDocs = reader.numDocs();
filesToDelete = new HashMap<Integer,File>();

for (int i = 0; i < numDocs; i++)
{
File file = new File(reader.document(i).get("path"));
System.out.println("Files: " + file);

This is another class snippet where I add documents
------------------------------------------------------------------------------------------------------
parser = new TextParser(file);
parser.parse();

Document doc = new Document();
String path = file.getPath();
Field relativeURLField = new StringField("path",path, Field.Store.YES);
doc.add(relativeURLField);

Field lastModified = new LongField("date", file.lastModified(), Field.Store.YES);
doc.add(lastModified);

Field bodyField = new TextField("body",parser.getBody(), Field.Store.NO);
doc.add(bodyField);

indexWriter.updateDocument(new Term("path",path),doc);

And this is where I delete documents
-------------------------------------------------------------------------

Directory dir = FSDirectory.open(indexFolder);
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_41);
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_41, analyzer);
iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
indexWriter = new IndexWriter(dir, iwc);

TermQuery query = new TermQuery(new Term("path",file.getPath()));

Directory dir = FSDirectory.open(mIndexFolder);
IndexReader reader = DirectoryReader.open(dir);

IndexSearcher is = new IndexSearcher(reader);
TopDocs topDocs = is.search(query, 100);
System.out.println("hits " + topDocs.totalHits);

indexWriter.deleteDocuments(new TermQuery(new Term("path",file.getPath())));

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message