Skip to content

Commit

Permalink
Fix failure in test from #2708 (#2709)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-4 authored Feb 3, 2025
1 parent a5d3479 commit e1f735e
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/main/java/io/anserini/server/SearchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import org.apache.lucene.document.Document;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -116,7 +118,12 @@ public List<Map<String, Object>> search(String query, int hits,
public Map<String, Object> getDocument(String docid) {
if (!isHnswIndex) throw new IllegalArgumentException("getDocument is only supported for HNSW indexes");
try (SimpleSearcher searcher = new SimpleSearcher(indexDir)) {
String raw = searcher.doc(docid).get(Constants.RAW);
Document lucene_document = searcher.doc(docid);
if (lucene_document == null) {
return Map.of("error", "Document not found: " + docid);
}

String raw = lucene_document.get(Constants.RAW);
Map<String, Object> candidate = new LinkedHashMap<>();
if (raw != null) {
JsonNode rootNode = mapper.readTree(raw);
Expand All @@ -131,7 +138,7 @@ public Map<String, Object> getDocument(String docid) {
return candidate;
} catch (Exception e) {
e.printStackTrace();
return Map.of();
return Map.of("error", "Error retrieving document: " + e.getMessage());
}
}

Expand All @@ -151,8 +158,15 @@ public void setEfSearchOverride(String value) {
if (value == null || value.trim().isEmpty()) {
throw new IllegalArgumentException("efSearch cannot be empty");
}
validateSettings(Integer.parseInt(value), getEncoderOverride(), getQueryGeneratorOverride());
indexOverrides.put("efSearch", Integer.parseInt(value));

int efSearch;
try {
efSearch = Integer.parseInt(value.trim());
} catch (NumberFormatException e) {
throw new IllegalArgumentException("efSearch must be a valid integer, but got: " + value);
}
validateSettings(efSearch, getEncoderOverride(), getQueryGeneratorOverride());
indexOverrides.put("efSearch", efSearch);
}

public void setEncoderOverride(String value) {
Expand Down

0 comments on commit e1f735e

Please sign in to comment.