Skip to content

Search results debugging #4194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2011, Jens Elkner.
* Portions Copyright (c) 2017, 2020, Chris Fraire <cfraire@me.com>.
*/
Expand All @@ -44,7 +44,6 @@
import org.apache.lucene.analysis.charfilter.HTMLStripCharFilter;
import org.apache.lucene.document.DateTools;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.StoredFields;
import org.apache.lucene.search.IndexSearcher;
Expand Down Expand Up @@ -76,22 +75,22 @@ private Results() {
}

/**
* Create a has map keyed by the directory of the document found.
* Create a hash map keyed by the directory of the document found.
*
* @param searcher searcher to use.
* @param hits hits produced by the given searcher's search
* @param startIdx the index of the first hit to check
* @param stopIdx the index of the last hit to check
* @return a (directory, hitDocument) hashmap
* @throws CorruptIndexException
* @throws IOException
* @return a (directory, list of hitDocument) hashmap
* @throws IOException when index cannot be read
*/
private static Map<String, ArrayList<Integer>> createMap(
IndexSearcher searcher, ScoreDoc[] hits, int startIdx, long stopIdx)
throws CorruptIndexException, IOException {
IndexSearcher searcher, ScoreDoc[] hits, int startIdx, long stopIdx) throws IOException {

LinkedHashMap<String, ArrayList<Integer>> dirHash =
new LinkedHashMap<>();
LOGGER.log(Level.FINEST, "directory hash contents for search hits ({0},{1}):",
new Object[]{startIdx, stopIdx});

LinkedHashMap<String, ArrayList<Integer>> dirHash = new LinkedHashMap<>();
StoredFields storedFields = searcher.storedFields();
for (int i = startIdx; i < stopIdx; i++) {
int docId = hits[i].doc;
Expand All @@ -102,10 +101,16 @@ private static Map<String, ArrayList<Integer>> createMap(
continue;
}

if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, "{0}: {1}", new Object[]{docId, rpath});
}

String parent = rpath.substring(0, rpath.lastIndexOf('/'));
ArrayList<Integer> dirDocs = dirHash.computeIfAbsent(parent, k -> new ArrayList<>());
dirDocs.add(docId);
}


return dirHash;
}

Expand All @@ -117,15 +122,13 @@ private static String getTags(File basedir, String path, boolean compressed) {
} catch (Exception e) {
String fnm = compressed ? TandemPath.join(basedir + path, ".gz") :
basedir + path;
LOGGER.log(Level.WARNING, "An error reading tags from " + fnm, e);
LOGGER.log(Level.WARNING, String.format("An error reading tags from '%s'", fnm), e);
}
return "";
}

/** Return a reader for the specified xref file. */
private static Reader getXrefReader(
File basedir, String path, boolean compressed)
throws IOException {
private static Reader getXrefReader(File basedir, String path, boolean compressed) throws IOException {
/*
* For backward compatibility, read the OpenGrok-produced document
* using the system default charset.
Expand Down Expand Up @@ -160,9 +163,9 @@ private static Reader getXrefReader(
* @throws IOException I/O exception
* @throws ClassNotFoundException class not found
*/
public static void prettyPrint(Writer out, SearchHelper sh, int start,
long end)
public static void prettyPrint(Writer out, SearchHelper sh, int start, long end)
throws HistoryException, IOException, ClassNotFoundException {

Project p;
String contextPath = sh.getContextPath();
String ctxE = Util.uriEncodePath(contextPath);
Expand Down