[
https://issues.apache.org/jira/browse/LUCENE-6983?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15108215#comment-15108215
]
uygar yuzsuren edited comment on LUCENE-6983 at 1/20/16 8:38 AM:
-----------------------------------------------------------------
Ok, I will looked more into the documentation.
On the other hand, I already made the test with a simple IndexSearcher code
taken from the documentation and it returned duplicates. I think this should be
one of the most basic functionalities of Lucene, which shouldn't require an
additional configuration option, that is why I didn't go deeper into the docs.
public static void main(String[] args) {
try {
Analyzer analyzer = new StandardAnalyzer();
Path path = Paths.get("C:\\LUCENE\\INDEX");
Directory directory = FSDirectory.open(path);
// Now search the index:
DirectoryReader ireader =
DirectoryReader.open(directory);
IndexSearcher isearcher = new IndexSearcher(ireader);
// Parse a simple query that searches for "text":
QueryParser parser = new QueryParser("webaddress",
analyzer);
Query query = parser.parse("lucene");
ScoreDoc[] hits = isearcher.search(query,
100).scoreDocs;
// Iterate through the results:
for (int i = 0; i < hits.length; i++) {
Document hitDoc = isearcher.doc(hits[i].doc);
System.out.println(hitDoc.get("entityid") + "/"
+ hits[i].score);
}
ireader.close();
directory.close();
} catch (IOException | ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
was (Author: uygaryuzsuren):
Ok, I will looked more into the documentation.
On the other hand, I already made the test with a simple IndexSearcher code
taken from the documentation and it returned duplicates. I think this should be
one of the most basic functionality of Lucene, which shouldn't require an
additional configuration option, that is why I didn't go deeper into the docs.
public static void main(String[] args) {
try {
Analyzer analyzer = new StandardAnalyzer();
Path path = Paths.get("C:\\LUCENE\\INDEX");
Directory directory = FSDirectory.open(path);
// Now search the index:
DirectoryReader ireader =
DirectoryReader.open(directory);
IndexSearcher isearcher = new IndexSearcher(ireader);
// Parse a simple query that searches for "text":
QueryParser parser = new QueryParser("webaddress",
analyzer);
Query query = parser.parse("lucene");
ScoreDoc[] hits = isearcher.search(query,
100).scoreDocs;
// Iterate through the results:
for (int i = 0; i < hits.length; i++) {
Document hitDoc = isearcher.doc(hits[i].doc);
System.out.println(hitDoc.get("entityid") + "/"
+ hits[i].score);
}
ireader.close();
directory.close();
} catch (IOException | ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
> IndexWriter.updateDocument on FSDirectory does not work Ver.5.4.0
> -----------------------------------------------------------------
>
> Key: LUCENE-6983
> URL: https://issues.apache.org/jira/browse/LUCENE-6983
> Project: Lucene - Core
> Issue Type: Bug
> Components: core/index
> Affects Versions: 5.4
> Environment: Windows 8, Java 1.8.0_60
> Reporter: uygar yuzsuren
>
> I try to create a simple index and then update documents (with
> IndexWriter.updateDocuments). When I use RAMDirectory it works fine
> (IndexWriter.numDocs returns correct value, IndexSearcher.search returns
> correct hits). However, when I use FSDirectory it creates duplicate
> documents, and IndexSearcher returns multiple documents with same key field
> values. Here is the code excerpt:
> //This code is in a thread and it updates documents with regular intervals,
> say 1 min.
> Analyzer analyzer = new StandardAnalyzer();
> try {
> Path path = Paths.get(indexDirectory);
> Directory directory = FSDirectory.open(path);
> IndexWriterConfig config = new IndexWriterConfig(analyzer);
> IndexWriter iwriter = new IndexWriter(directory, config);
> System.out.println("Document count=" + iwriter.numDocs());
> for (Company newCompany : newCompanies)
> { Document doc = new Document(); doc.add(new Field("entityid", "Company" +
> newCompany.getId().toString(), TextField.TYPE_STORED)); doc.add(new
> Field("companyname", newCompany.getName(), TextField.TYPE_NOT_STORED)); Term
> term = new Term("entityid", "Company" + newCompany.getId().toString());
> iwriter.updateDocument(term, doc); }
> iwriter.flush();
> iwriter.commit();
> System.out.println("Document count2=" + iwriter.numDocs());
> iwriter.close();
> } catch (IOException e1)
> { e1.printStackTrace(); }
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]