Reputation: 3085
So I have an index that is created by lucene (Java). I am trying to search the index as following
TopDocs result = searcher.search(query, maxResults);
for (ScoreDoc scoreDoc : result.scoreDocs) {
Document doc = searcher.doc(scoreDoc.doc);
LogService.logger().warning("Title| " + doc.get("title"));
LogService.logger().warning("URL| " + doc.get("url"));
The code prints the url field but prints null
for the title field.
My first guess was that there might be an issue with the field name or the content is actually null.
However I double checked with Lucene Luke (GUI-based inspection tool) and the field name seems to be OK and the content is definitely not null
.
I am not sure what could be the reason for that .. any suggestions ?
P.S: Both indexing and searching were performed using the same lucene version (6.2.1)
Upvotes: 0
Views: 515
Reputation: 33341
Well, you haven't provided enough information to be sure, but I'd bet that field isn't stored. If you are using a TextField
, and using a Reader
or TokenStream
as the source, for instance, the field will not be stored, and will be searchable, but you will not be able to retrieve it.
You can make a TextField stored like:
Field titleField = new TextField("title", "The Sun Also Rises", Field.Store.YES);
Upvotes: 3