Skip to content
Permalink
Browse files

Prevent duplication of Solr query highlight fields parameters

That was caused by concurrent modifications (with addHighlightField()
function) to the same SolrQuery instance when requesting Solr on remote
peers in p2p search.
  • Loading branch information...
luccioman committed May 14, 2018
1 parent 4f0ab31 commit f511e16d50a71dbce3f0c19f21943dee877d864f
Showing with 25 additions and 23 deletions.
  1. +7 −23 source/net/yacy/peers/Protocol.java
  2. +18 −0 source/net/yacy/search/query/QueryParams.java
@@ -74,7 +74,6 @@

import net.yacy.migration;
import net.yacy.cora.date.GenericFormatter;
import net.yacy.cora.document.analysis.Classification;
import net.yacy.cora.document.analysis.Classification.ContentDomain;
import net.yacy.cora.document.encoding.ASCII;
import net.yacy.cora.document.encoding.UTF8;
@@ -1021,8 +1020,6 @@ public SearchResult(
}
}

private final static CollectionSchema[] snippetFields = new CollectionSchema[]{CollectionSchema.description_txt, CollectionSchema.h4_txt, CollectionSchema.h3_txt, CollectionSchema.h2_txt, CollectionSchema.h1_txt, CollectionSchema.text_t};

/**
* A task dedicated to requesting a Solr instance
*/
@@ -1199,19 +1196,6 @@ protected static int solrQuery(
solrQuery.setStart(offset);
solrQuery.setRows(count);

// set highlighting query attributes
if (event.query.contentdom == Classification.ContentDomain.TEXT || event.query.contentdom == Classification.ContentDomain.ALL) {
solrQuery.setHighlight(true);
solrQuery.setHighlightFragsize(SearchEvent.SNIPPET_MAX_LENGTH);
//solrQuery.setHighlightRequireFieldMatch();
solrQuery.setHighlightSimplePost("</b>");
solrQuery.setHighlightSimplePre("<b>");
solrQuery.setHighlightSnippets(5);
for (CollectionSchema field: snippetFields) solrQuery.addHighlightField(field.getSolrFieldName());
//System.out.println("*** debug-query-highligh ***:" + ConcurrentLog.stackTrace());
} else {
solrQuery.setHighlight(false);
}
boolean localsearch = target == null || target.equals(event.peers.mySeed());
Map<String, ReversibleScoreMap<String>> facets = new HashMap<String, ReversibleScoreMap<String>>(event.query.facetfields.size());
Map<String, LinkedHashSet<String>> snippets = new HashMap<String, LinkedHashSet<String>>(); // this will be a list of urlhash-snippet entries
@@ -1322,15 +1306,15 @@ protected static int solrQuery(
}

// evaluate snippets
Map<String, Map<String, List<String>>> rawsnippets = rsp[0].getHighlighting(); // a map from the urlhash to a map with key=field and value = list of snippets
final Map<String, Map<String, List<String>>> rawsnippets = rsp[0].getHighlighting(); // a map from the urlhash to a map with key=field and value = list of snippets
if (rawsnippets != null) {
nextsnippet: for (Map.Entry<String, Map<String, List<String>>> re: rawsnippets.entrySet()) {
Map<String, List<String>> rs = re.getValue();
for (CollectionSchema field: snippetFields) {
if (rs.containsKey(field.getSolrFieldName())) {
List<String> s = rs.get(field.getSolrFieldName());
nextsnippet: for (final Map.Entry<String, Map<String, List<String>>> re: rawsnippets.entrySet()) {
final Map<String, List<String>> rs = re.getValue();
for (final String field: solrQuery.getHighlightFields()) {
if (rs.containsKey(field)) {
final List<String> s = rs.get(field);
if (s.size() > 0) {
LinkedHashSet<String> ls = new LinkedHashSet<String>();
final LinkedHashSet<String> ls = new LinkedHashSet<String>();
ls.addAll(s);
snippets.put(re.getKey(), ls);
continue nextsnippet;
@@ -115,6 +115,9 @@ public String toString() {
//missing: namespace
}

/** List of Solr fields used to extract text snippets when requesting the Solr index */
private final static CollectionSchema[] SOLR_SNIPPET_FIELDS = new CollectionSchema[]{CollectionSchema.description_txt, CollectionSchema.h4_txt, CollectionSchema.h3_txt, CollectionSchema.h2_txt, CollectionSchema.h1_txt, CollectionSchema.text_t};

public static final Bitfield empty_constraint = new Bitfield(4, "AAAAAA");
public static final Pattern catchall_pattern = Pattern.compile(".*");

@@ -635,6 +638,21 @@ private SolrQuery solrQuery(final boolean getFacets, final List<String> filterQu
if (bq.length() > 0) params.setParam(DisMaxParams.BQ, bq.split("[\\r\\n]+")); // split on any sequence consisting of CR and/or LF
if (bf.length() > 0) params.setParam("boost", bf); // a boost function extension, see http://wiki.apache.org/solr/ExtendedDisMax#bf_.28Boost_Function.2C_additive.29

// set highlighting query attributes
if (this.contentdom == Classification.ContentDomain.TEXT || this.contentdom == Classification.ContentDomain.ALL) {
params.setHighlight(true);
params.setHighlightFragsize(SearchEvent.SNIPPET_MAX_LENGTH);
//params.setHighlightRequireFieldMatch();
params.setHighlightSimplePost("</b>");
params.setHighlightSimplePre("<b>");
params.setHighlightSnippets(5);
for (final CollectionSchema field: SOLR_SNIPPET_FIELDS) {
params.addHighlightField(field.getSolrFieldName());
}
} else {
params.setHighlight(false);
}

// prepare result
ConcurrentLog.info("Protocol", "SOLR QUERY: " + params.toString());
this.cachedQuery = params;

0 comments on commit f511e16

Please sign in to comment.
You can’t perform that action at this time.