You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Jenny <je...@gmail.com> on 2017/03/29 15:13:30 UTC
Index error
Dear All,
I am writing an index for my project. Basically, I need to index documents
that have the following string parts
(s1=uri1, s2=url1##sameAs.org service@@url2##source KG owl:sameas@@).
To do so, I am using the following code:
TO ADD:
String urlString="subA"
String tmp = "url1##sameAs.org service@@url2##source KG owl:sameas@@"
StringField url = new StringField("URL", urlAddress,
Field.Store.YES);
StringField cSet = new StringField("ClassSet", tmp,
Field.Store.YES);
doc.add(url);
doc.add(cSet);
indexWriter.addDocument(doc);
indexWriter.commit();
TO GET:
//..prepare the query
BooleanQuery query = new BooleanQuery();
query.add(new TermQuery(new Term("URL", urlAddress)),
BooleanClause.Occur.MUST);
//..find the docs by executing the query
int hitsPerPage = 1;
TopScoreDocCollector collector =
TopScoreDocCollector.create(hitsPerPage);
searcher.search(query, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
if (hits.length > 0) {
//..retrieve the related doc
int docId = hits[0].doc;
Document d = searcher.doc(docId);
if (d != null) {
ArrayList<TargetEntity> newTargetEntityList= new
ArrayList();
//String cSet = d.get("ClassSet");
String cSet = d.getField("ClassSet").stringValue();
System.out.println("[addSbjSameAsListNew] URL = "
+d.getField("URL").stringValue());
System.out.println("[addSbjSameAsListNew] ClassSet FIELD =
" +d.getField("ClassSet").stringValue());
The point is that when testing it on the above example (urlString="subA"),
I get as output "url2##source KG owl:sameas@@" and not "url1##sameAs.org
service@@url2##source KG owl:sameas@@".
I tested the above example with both the StandardAnalyzer() and
KeywordAnalyzer() on the Lucene 5.5.4.
What is wrong? What am I missing?
Many Thanks in advance for your help.
Jenny
Re: Index error
Posted by Trejkaz <tr...@trypticon.org>.
What if totalHits > 1?
TX
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org