Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.7.1-jre</version>
<version>33.7.2-jre</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private void reconcileMorgueRecords(MorgueIndexer morgueIndex) {
if (removed > 0) {
LOG.info("Removed {} stale tombstone(s) from the morgue index", removed);
}
} catch (SolrServerException | IOException ex) {
} catch (SolrServerException | RemoteSolrException | IOException ex) {
LOG.warn("Could not reconcile the morgue index with the live index", ex);
}
}
Expand Down Expand Up @@ -289,14 +289,18 @@ void startImport() throws MalformedURLException {
} finally {
try {
solrBridge.commit();
} catch (SolrServerException | RemoteSolrException | IOException e) {
LOG.error("cannot commit:\n", e);
}
try {
reconcileMorgueRecords(morgueLookup);
buildSuggesterIndex();
solrBridge.commit();
} catch (SolrServerException | RemoteSolrException | IOException e) {
if (e instanceof SocketTimeoutException || e.getCause() instanceof SocketTimeoutException) {
LOG.warn("Retrieved a timeout while waiting for building of autocompletion index to complete.", e);
} else {
LOG.error("cannot commit:\n", e);
LOG.error("Could not build the autocompletion index:\n", e);
}
} finally {
resourceAvailabilityCheckerMonitor.shutdown();
Expand Down Expand Up @@ -646,9 +650,9 @@ protected List<List<File>> getFilesFromDataRoot(File rootFile) {
* Builds suggester index for autocompletion
*
* @throws SolrServerException
* @throws MalformedURLException
* @throws IOException
*/
private void buildSuggesterIndex() throws SolrServerException, MalformedURLException, IOException {
private void buildSuggesterIndex() throws SolrServerException, IOException {
LOG.info("Building index for autocompletion.");
HashMap<String, String> paramMap = new HashMap<>();
paramMap.put("qt", "/suggest");
Expand All @@ -661,10 +665,10 @@ private void buildSuggesterIndex() throws SolrServerException, MalformedURLExcep
* Updates documents in Solr with their hierarchy weight and lists of
* related resources (hasPart & isPartOf)
*
* @throws SolrServerException
* @throws DocumentStoreException
* @throws MalformedURLException
*/
private synchronized void updateDocumentHierarchy(ResourceStructureGraph resourceStructureGraph) throws DocumentStoreException, MalformedURLException, IOException {
private synchronized void updateDocumentHierarchy(ResourceStructureGraph resourceStructureGraph) throws DocumentStoreException, IOException {
LOG.info(resourceStructureGraph.printStatistics(0));
final AtomicInteger updateCount = new AtomicInteger();
final Iterator<CmdiVertex> vertexIter = resourceStructureGraph.getFoundVertices().iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.stream.Collectors;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpJdkSolrClient;
import org.apache.solr.client.solrj.request.QueryRequest;
Expand Down Expand Up @@ -287,7 +288,7 @@ private List<String> idsPresentInLiveIndex(List<String> ids, String idField) thr
liveItemsQuery.setFields(idField);
liveItemsQuery.setRows(ids.size());

final QueryRequest queryRequest = new QueryRequest(liveItemsQuery);
final QueryRequest queryRequest = new QueryRequest(liveItemsQuery, SolrRequest.METHOD.POST);
// read the live index through the 'fast' handler, which does not collapse results
queryRequest.setPath(FacetConstants.SOLR_REQUEST_HANDLER_FAST);
queryRequest.setBasicAuthCredentials(config.getSolrUserReadOnly(), config.getSolrUserReadOnlyPass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.common.util.NamedList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* DAO that delivers suggestions for incomplete terms (autocomplete function)
Expand All @@ -22,6 +24,8 @@
*/
public class AutoCompleteServiceImpl extends SolrDaoImpl implements AutoCompleteService {

private final static Logger logger = LoggerFactory.getLogger(AutoCompleteServiceImpl.class);

private static final int MAX_SUGGESTIONS = 10;

public AutoCompleteServiceImpl(SolrClient solrClient, VloConfig config, FieldNameService fieldNameService) {
Expand All @@ -37,9 +41,13 @@ public Iterator<String> getChoices(String input) {
query.setQuery(input.toLowerCase());
final QueryRequest req = new QueryRequest(query);
req.setPath("/suggest");
// fireRawQuery bypasses QueryResponse which crashes on the "suggest" key
// with solrj 9 + Solr 8 (LinkedHashMap vs NamedList cast)
return parseSuggestions(fireRawQuery(req));
try {
return parseSuggestions(fireRawQuery(req));
} catch (RuntimeException ex) {
logger.warn("Could not get suggestions for '{}': {}", input, ex.toString());
logger.debug("Suggestion request failed", ex);
return Collections.emptyIterator();
}
}

private Iterator<String> parseSuggestions(NamedList<Object> raw) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import java.util.List;
import java.util.Map;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.util.NamedList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.empty;
import org.junit.jupiter.api.Test;

public class AutoCompleteServiceImplTest {
Expand Down Expand Up @@ -42,6 +44,19 @@ protected NamedList<Object> fireRawQuery(QueryRequest req) {
assertThat(actual, contains("language", "languages", "language05"));
}

@Test
public void solrErrorGivesNoSuggestionsInsteadOfException() {
// e.g. HTTP 500 "Lookup not supported at this time" from an unbuilt suggester
AutoCompleteServiceImpl service = new AutoCompleteServiceImpl(null, new VloConfig(), stubFieldNames()) {
@Override
protected NamedList<Object> fireRawQuery(QueryRequest req) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Lookup not supported at this time");
}
};

assertThat(Lists.newArrayList(service.getChoices("lang")), empty());
}

private static FieldNameService stubFieldNames() {
return new FieldNameService() {
@Override public String getFieldName(FieldKey key) { return "id"; }
Expand Down
Loading