Skip to content

Commit

Permalink
Changes for liveness and readiness probe
Browse files Browse the repository at this point in the history
  • Loading branch information
nshweta90 committed May 24, 2024
1 parent 7650dca commit 2799448
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import eu.europeana.fulltext.search.config.SearchConfig;
import eu.europeana.fulltext.search.model.query.EuropeanaId;
import eu.europeana.fulltext.search.model.response.Debug;
import eu.europeana.fulltext.util.RequestUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -41,7 +42,6 @@ public class SolrHighlightQueryImpl implements SolrHighlightQuery {

@Autowired
private SolrTemplate solrTemplate;

@Value("${spring.data.solr.core:}")
private String solrCore;
@Value("${spring.data.solr.hl.maxAnalyzedChars:}")
Expand All @@ -56,7 +56,6 @@ public Map<String, List<String>> getHighlightsWithOffsets(EuropeanaId europeanaI
if (debug != null) {
debug.setSolrQuery(q.toQueryString());
}

// do query
QueryResponse response;
try {
Expand All @@ -67,7 +66,6 @@ public Map<String, List<String>> getHighlightsWithOffsets(EuropeanaId europeanaI
} catch (SolrServerException | IOException e) {
throw new EuropeanaApiException("Error querying Solr", e);
}

// process results
SolrDocumentList list = response.getResults();
if (list.getNumFound() == 0) {
Expand All @@ -83,7 +81,6 @@ SolrQuery createQuery(EuropeanaId europeanaId, String query, int maxSnippets) {
sq.setRows(1); // we expect 1 issue to return anyway
sq.setTimeAllowed(SearchConfig.QUERY_TIME_ALLOWED);
sq.setFields(EUROPEANA_ID_FIELD); // just 1 field, so we limit the amount of data that is returned

sq.setHighlight(true)
.setHighlightSnippets(maxSnippets)
.setHighlightFragsize(0) // we need to entire fragment because that includes the imageId
Expand All @@ -99,11 +96,12 @@ SolrQuery createQuery(EuropeanaId europeanaId, String query, int maxSnippets) {
return sq;
}


@NotNull
private static String filterAndUpdateQueryChars(String query) {
//EA- https://europeana.atlassian.net/browse/EA-3787
if(StringUtils.isNotEmpty(query))
query =query.replaceAll(REGEX_FOR_CHARS_TO_FILTER, "") ;
return ClientUtils.escapeQueryChars(query);
return RequestUtils.escapeQueryChars(query);
}

}
22 changes: 22 additions & 0 deletions api/src/main/java/eu/europeana/fulltext/util/RequestUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.europeana.fulltext.util;

import eu.europeana.fulltext.exception.InvalidRequestParamException;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
Expand All @@ -12,6 +13,9 @@ public class RequestUtils {
public static final String PROFILE_TEXT = "text";
public static final String PROFILE_DEBUG = "debug";

public RequestUtils() {
}

public static List<String> extractProfiles(String profileParam) throws InvalidRequestParamException {
// Now profile can be profile=text OR
// profile=text,debug OR profile=debug (for error stack trace purpose)
Expand All @@ -28,4 +32,22 @@ public static List<String> extractProfiles(String profileParam) throws InvalidRe
return profiles;
}

/** Method is similar to ClientUtils.escapeQueryChars
* Method does not escape the '"' character
* See EA-3787
* @param
* @return
*/
public static String escapeQueryChars(String s) {
StringBuilder stringBuilder = new StringBuilder();
for (char c : s.toCharArray()) {
if (Character.isWhitespace(c) || Set.of('+', '-', '!', '(', ')', ':',
'^', '[', ']', '{', '}', '~', '*', '?', '|', '&', ';', '/').contains(c)) {
stringBuilder.append('\\');
}
stringBuilder.append(c);
}
return stringBuilder.toString();
}

}

0 comments on commit 2799448

Please sign in to comment.