I find myself doing exactly the same, so such a tool would be wonderful. I sometimes use the Solr Query Debugger <https://chrome.google.com/webstore/detail/solr-query-debugger/gmpkeiamnmccifccnbfljffkcnacmmdl> Chrome plugin but that does not help with decoding the q parameter, only to more easily see all params and navigate explain. And sometimes I use https://explain.solr.pl/explains/new <https://explain.solr.pl/explains/new> for decoding explain. Lucene already parses the query string and builds a Lucene query, I wonder if it would be easiest to consume that Object graph with some kind of plugin to produce an indented view of the query. Or perhaps that could be a new display mode for debug=query as a standard feature?
Another option you have is of course to start sending your Solr queries as JSON DSL https://lucene.apache.org/solr/guide/7_6/json-query-dsl.html <https://lucene.apache.org/solr/guide/7_6/json-query-dsl.html> in the first place :) -- Jan Høydahl, search solution architect Cominvent AS - www.cominvent.com <http://www.cominvent.com/> > 8. jan. 2019 kl. 05:33 skrev Hullegård, Jimi > <jimi.hulleg...@svensktnaringsliv.se > <mailto:jimi.hulleg...@svensktnaringsliv.se>>: > > Hi, > > I often find myself having to analyze an already existing solr query. But > when the number of clauses and/or number of nested parentheses reach a > certain level I can no longer grasp what the query is about by just a quick > glance. Sometimes I can look at the code generating the query, but it might > be autogenerated in a complex way, or I might only have access to a log > output of the query. > > Here is an example query, based on a real query in our system: > > > system:(a) type:(x OR y OR z) date1:[* TO 2019-08-31T06:15:00Z/DAY+1DAYS] > ((boolean1:false OR date2:[* TO 2019-08-31T06:15:00Z/DAY-30DAYS])) > -date3:[2019-08-31T06:15:00Z/DAY+1DAYS TO *] (((*:* -date4:*) OR date5:* OR > date3:[* TO 2019-08-31T06:15:00Z/DAY+1DAYS])) > > > Here I find it quite difficult to what clauses are grouped together (using > parentheses). What I tend to do in these circumstances is to copy the query > into a simple text editor, and then manually add line breaks and indentation > matching the parentheses levels. > > For the query above, it would result in something like this: > > > system:(a) > type:(x OR y OR z) > date1:[* TO 2019-08-31T06:15:00Z/DAY+1DAYS] > ( > (boolean1:false OR date2:[* TO > 2019-08-31T06:15:00Z/DAY-30DAYS]) > ) > -date3:[2019-08-31T06:15:00Z/DAY+1DAYS TO *] > ( > ((*:* -date4:*) OR date5:* OR date3:[* TO > 2019-08-31T06:15:00Z/DAY+1DAYS]) > ) > > > But that is a slow process, and I might make a mistake that messes up the > interpretation completely. Especially when there are several levels of nested > parentheses. > > Does anyone know of any kind of tool that would help automate this? It > wouldn't have to format its output like my example, as long as it makes it > easier to see what start and end parentheses belong to each other, preferably > using multiple lines and indentation. > > A java tool would be perfect, because then I could easily integrate it into > our existing debugging tools, but an online formatter (like > http://jsonformatter.curiousconcept.com > <http://jsonformatter.curiousconcept.com/>) would also be very useful. > > Regards > /Jimi > > Svenskt Näringsliv behandlar dina personuppgifter i enlighet med GDPR. Här > kan du läsa mer om vår behandling och dina rättigheter, > Integritetspolicy<https://www.svensktnaringsliv.se/dataskydd/integritet-och-behandling-av-personuppgifter_697219.html?utm_source=sn-email&utm_medium=email > > <https://www.svensktnaringsliv.se/dataskydd/integritet-och-behandling-av-personuppgifter_697219.html?utm_source=sn-email&utm_medium=email>>