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 Apr 22, 2024
1 parent 138f61f commit 17444a0
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import eu.europeana.fulltext.search.config.SearchConfig;
import eu.europeana.fulltext.search.model.query.EuropeanaId;
import eu.europeana.fulltext.search.model.response.Debug;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.util.ClientUtils;
import org.apache.solr.common.SolrDocumentList;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.solr.core.SolrTemplate;
Expand All @@ -35,6 +37,7 @@ public class SolrHighlightQueryImpl implements SolrHighlightQuery {
private static final String HL_METHOD_PARAM = "hl.method";
private static final String HL_MAXANALYZEDCHARS_PARAM = "hl.maxAnalyzedChars";
private static final String EUROPEANA_ID_FIELD = "europeana_id";
public static final String REGEX_FOR_CHARS_TO_FILTER = "[{}<>]";

@Autowired
private SolrTemplate solrTemplate;
Expand Down Expand Up @@ -76,7 +79,7 @@ public Map<String, List<String>> getHighlightsWithOffsets(EuropeanaId europeanaI

SolrQuery createQuery(EuropeanaId europeanaId, String query, int maxSnippets) {
SolrQuery sq = new SolrQuery();
sq.setQuery(EUROPEANA_ID_FIELD + ":" + ClientUtils.escapeQueryChars(europeanaId.toString()));
sq.setQuery(EUROPEANA_ID_FIELD + ":" + filterAndUpdateQueryChars(europeanaId.toString()));
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
Expand All @@ -88,12 +91,19 @@ SolrQuery createQuery(EuropeanaId europeanaId, String query, int maxSnippets) {
.setHighlightSimplePost(SearchConfig.HIT_TAG_END)
.set(HL_EXTENDED_PARAM, "true")
.set(HL_METHOD_PARAM, "unified")
.set(HL_QUERY, ClientUtils.escapeQueryChars(query))
.set(HL_QUERY, filterAndUpdateQueryChars(query))
.set(HL_FIELDS, "fulltext.*");
if (maxAnalyzedChars != null) {
sq.set(HL_MAXANALYZEDCHARS_PARAM, String.valueOf(maxAnalyzedChars));
}
return sq;
}

@NotNull
private static String filterAndUpdateQueryChars(String query) {
if(StringUtils.isNotEmpty(query))
query =query.replaceAll(REGEX_FOR_CHARS_TO_FILTER, "") ;
return ClientUtils.escapeQueryChars(query);
}

}

0 comments on commit 17444a0

Please sign in to comment.