Solr call by curl for string that has space

I was using Solr at my work. Most of the products searching and filtering are well organzied if you use solr. Last month, i faced some issue about solr facets value can have string that has space.

My program is calling to solr host from curl something like that

    curl http://localhost:9090/solr/select?q=*:*&facet_catalogtype:Hot Deals

But it’s not working for this case in curl. And i find in many blog spots how to deals this blank value. There is some various solutions for this case.

Workaround combination

  - http://localhost:9090/solr/select?q=*:*&facet_catalogtype:"Hot Deals" ( only work on browser )
  - http://localhost:9090/solr/select?q=*:*&facet_catalogtype:Hot\ Deals ( only work on browser )
  - http://localhost:9090/solr/select?q=*:*&facet_catalogtype:Hot+Deals ( only work on browser )
  - http://localhost:9090/solr/select?q=*:*&facet_catalogtype:"Hot+Deals" ( correct one )

There is one note to be considered for this case

  • if the facet string has space, it need to be url encode.

     $value = "Hot Deals";
     http://localhost:9090/solr/select?q=*:*&facet_catalogtype:"urlencode($value)"
    
     Output 
     http://localhost:9090/solr/select?q=*:*&facet_catalogtype:"Hot+Deals"
    

Happy Coding !