zenogantner / MyMediaLite

recommender system library for the CLR (.NET)
http://mymedialite.net
499 stars 192 forks source link

Wrong files showing while querying the index path using lucene. #466

Closed Panda-Srujan closed 7 years ago

Panda-Srujan commented 7 years ago

Hi everyone,

I'm new to Lucene. I've an issue while querying the index file (path) while searching for a string in the files (say: doc files). I've looped through all the files using the following code.

string indexFileLocation = txtRootDirectory.Text.Trim();
            Lucene.Net.Store.Directory dir = Lucene.Net.Store.FSDirectory.GetDirectory(indexFileLocation,
                 false);
            Lucene.Net.Search.IndexSearcher searcher = new Lucene.Net.Search.IndexSearcher(dir, false);
            Lucene.Net.Index.Term searchTerm = new Lucene.Net.Index.Term("content", 
                 txtSearch.Text.Trim());
            Lucene.Net.Search.Query query = new Lucene.Net.Search.TermQuery(searchTerm);
            Lucene.Net.Search.Hits hits = searcher.Search(query);

for (int i = 0; i < hits.Length(); i++)
            {
                Lucene.Net.Documents.Document doc = hits.Doc(i);
                StringBuilder contentValue = new StringBuilder();
                contentValue.Append(doc.Get("content"));
                string id = doc.Get("id");
                lblSearchResults.Text += id + "<br />";
            }

But unfortunately, I've been getting the same search results, the same file name as follows.

repetition

I couldn't figure out if I'm doing wrong anywhere in my code. Please help me out.

Thanks in advance.

zenogantner commented 7 years ago

Hi. This has nothing to do with MyMediaLite, right?