apache / apache/lucene

Nested if-then-else in demo/SearchFiles.java [LUCENE-7846]

Open
#8,897 2 comments 0 reactions 0 assignees View on GitHub
affects-version:6.5.1 legacy-jira-label:easyfix legacy-jira-priority:Minor type:enhancement
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

/demo/src/java/org/apache/lucene/demo/SearchFiles.java

Line 181-191, nested if avoid the print of title if path is null.

Document doc = searcher.doc(hits[i].doc);
String path = doc.get("path");
if (path != null) {
System.out.println((i+1) + ". " + path);
String title = doc.get("title");
if (title != null) {
System.out.println(" Title: " + doc.get("title"));
}
} else {
System.out.println((i+1) + ". " + "No path for this document");
}

-----

unnested if-then-else to print the title even if path is null.

Document doc = searcher.doc(hits[i].doc);
String path = doc.get("path");
if (path != null) {
System.out.println((i+1) + ". " + path);
}
else {
System.out.println((i+1) + ". " + "No path for this document");
}

String title = doc.get("title");
if (title != null) {
System.out.println(" Title: " + title);
}
else {
System.out.println((i+1) + ". " + "No title for this document");
}

---
Migrated from [LUCENE-7846](https://issues.apache.org/jira/browse/LUCENE-7846) by www.jbigdata.fr, updated Jun 17 2017

Contributor guide

Open the contributing guide

Research direction

Start in demo/src/java/org/apache/lucene/demo/SearchFiles.java around lines 181-191 and inspect how path and title are reported for each search hit. Verify the demo output for documents with and without path or title, and consider the issue complete when title reporting is independent of path reporting and missing values produce the requested messages.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.