local param not working in solr 8 but working in solr 5

738 views Asked by At

I am migrating from solr 5.5 to solr 8. Query for solr 5.5 looks like -

qt=/dismax
product_fields_Ref1=product_concept^279841
sku_and_product_fields_Ref1=silhouette_concept^234256 $product_fields_Ref1
product_phrase_Ref2=pant
concept_with_synonyms_ref1=({!edismax2 qf=$sku_and_product_fields_Ref1     v=$product_phrase_Ref2})
top_concept_query_ref= (+({!maxscore v=$concept_with_synonyms_ref1}) ) 
productQueryRef3=+(+({!query v=$cq})) +( ({!maxscore v=$top_concept_query_ref}) ) 
sq=+{!lucene v=$productQueryRef3}
q={!parent tag=top which=$pq score=max v=$sq}

But is giving error on solr 8.0 with error -

Error from server at http://localhost:8080/products: org.apache.solr.search.SyntaxError: Query Field '$product_fields_Ref1' is not a valid field name

If I modify query like this (remove the variable product_fields_Ref1 and append the value directly in sku_and_product_fields_Ref1) -

qt=/dismax
sku_and_product_fields_Ref1=silhouette_concept^234256 product_concept^279841
product_phrase_Ref2=pant
concept_with_synonyms_ref1=({!edismax2 qf=$sku_and_product_fields_Ref1     v=$product_phrase_Ref2})
top_concept_query_ref= (+({!maxscore v=$concept_with_synonyms_ref1}) ) 
productQueryRef3=+(+({!query v=$cq})) +( ({!maxscore v=$top_concept_query_ref}) ) 
sq=+{!lucene v=$productQueryRef3}
q={!parent tag=top which=$pq score=max v=$sq}

Problem is I can not modify this query since the value of param "product_fields_Ref1" are being compiled from a large number of places. I am using defType=dismax only. Can any one guide what needs to be fixed?

2

There are 2 answers

0
Vibhav Singh Rohilla On BEST ANSWER

I went through the source code of "org.apache.solr.search.ExtendedDismaxQParser" and found out the is a new validation check added which DOES NOT allow local parameter in qf field edismax parser (this check has been introduced starting solr 8.0.0).

Check works like this -

any parameter coming in qf MUST match a field in schema (I am not using schema-less mode) of the core. method is

validateQueryFields(up);

This executes in

public Query parse() throws SyntaxError { ... }

of

org.apache.solr.search.ExtendedDismaxQParser

I got this working by creating my own custom parser and removed this validator after overriding the parse() method.

1
Hector Correa On

Support for Local Parameters has changed significantly in more recent versions of Solr (see https://lucene.apache.org/solr/guide/7_5/solr-upgrade-notes.html#solr-7-2)

The only way that I have been able to get some of the behavior back is by setting lucene as the default parser in solrconfig.xml and then passing the local parameters in the query, for example: q={!dismax qf=$param1}coffee

I understand that you can get back the old behavior by switching to LuceneMatchVersion 7.1.0 but that change did not work for me.