Skip to content

Instantly share code, notes, and snippets.

@softwaredoug
Last active September 6, 2017 15:24
Show Gist options
  • Save softwaredoug/38700b222ebaa246989c to your computer and use it in GitHub Desktop.
Save softwaredoug/38700b222ebaa246989c to your computer and use it in GitHub Desktop.
Solr Local Params -- Secret Manual

Infinite Recursion Errors

What's wrong with this?

q=cats&bq={!edismax qf=title v=$q}

Well it turns out that the local params carries the external params with it. So the bq will get applied to itself, resulting in "Infinite Recursion Errors".

The fix is:

q=cats&bq={!edismax qf=title v=$q bq=}

Stubbing out multiple parameters

You will have similar issues if you have a query within a boost function, ie:

q=cats&qqq={!edismax qf=title v=$q bq=}&bf=query($qqq)

You need to stub out bq and bf, but ah herein lies the rub (isn't Solr awesome) you need to stub out the first param differently than the last.

This won't do what you think:

q=cats&qqq={!edismax qf=title v=$q bq= bf=}&bf=query($qqq)

Instead you need to do:

q=cats&qqq={!edismax qf=title v=$q bq='' bf=}&bf=query($qqq)

And no this doesn't appear to do the same thing

q=cats&qqq={!edismax qf=title v=$q bq='' bf=''}&bf=query($qqq)

Oh Solr you're fun :)

Macro substitution and errors loading Solr Config

Solr 5.1 introduced a different macro substitution synatx. As opposed to parameter substitution, $q, this is more of a templating system letting you sprinkle {$q} or {$qqq} wherever you want. IE:

bq={!complexphrase df=title}"${q}"

Now you'd think you could port it to your Solrconfig:

<str name="bq">{!complexphrase df=title}"${q}"</str>

But this gives an error:

Error: org.apache.solr.common.SolrException: No system property or default value specified for q value:{!complexphrase df=title}"${q}"

This is because ${q} syntax overlaps with solrconfigs Java property syntax.

To fix, set the default value for the Java property to ${q}:

<str name="bq">{!complexphrase df=title}"${q:${q}}"</str>
@brigaldies
Copy link

Gotta love Solr!
So, I had been assuming that bq= and bq='' meant the same thing. Apparently not!? I'm anxiously waiting for your "episode #2" of this topic where you explain the differences between the last two expressions. :-)

@dsmiley
Copy link

dsmiley commented Sep 5, 2017

Hmmm; the ${q:${q}} in solrconfig.xml looks more complex than it needs to be. A few weeks ago I ran into this and found that the dollar sign can be escaped in solrconfig.xml by adding an extra. Using your example, this would be $${q}. Not too bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment