Javascript SOLR URL Filter Query Parser

59 Views Asked by At

We do have filter queries like this in SOLR:

?pageSize=30&currentPage=0&q=blahblah:relevance,sortingNumber-asc:productgroup:houseHoldSoap:soapVariant:TMZ:lengthToBeginningOfEdge:381.0-to-381.0

Now we need a javascript object of this object. So we need to parse it somehow, to get something like this:

{
  pageSize: 30,
  currentPage: 0,
  sorting: ["relevance", "sortingNumber-asc"],
  filterQuery: [
        {"productgroup": "houseHoldSoap"},
        {"soapVariant": "TMZ"},
        {"lengthToBeginningOfEdge": "381.0-to-381.0" }
  ]
}

We tried to write our own parser because we could not find any existing library, but it's almost impossible because the syntax is so bad. For example there are key-value items like "productgroup:houseHoldSoap" but other filter values like sorting is just a single value and all are seperated by ":" ...

Is there any good way to achieve this? Like a Javascript function or SOLR library, that we can just pass the URL string and it returns a proper javascript object?

0

There are 0 best solutions below