pythonsolrpysolr

I want to run a query in solr having the special character & and %


I am having trouble running a query using Pysolr when & and % appear in the query. The rest of the special characters can be handled using a '\' but '&' and '%' are a different case. the following query sends an error, but when & and % are removed it works fine. Can someone help?

http:///1.254.254.254:8983solr/dovecottmail/select?fq=user:%22user@xyz.com%22&indent=on&wt=python&q="https://aws.amazon.com/marketplace/pp/b074m84rjm\%qid=1507365354908\&amp\;sr=0-1\&amp\;ref_=srh_res_product_title"


Solution

  • You can encode your query parameter while passing to solr.

    Please find below example.

      http://1.254.254.254:8983:solr/dovecottmail/select?fq=user:%22user@xyz.com%22&indent=on&wt=python&q=%22https%3A%2F%2Faws.amazon.com%2Fmarketplace%2Fpp%2Fb074m84rjm%5C%25qid%3D1507365354908%5C%26amp%5C%3Bsr%3D0-1%5C%26amp%5C%3Bref_%3Dsrh_res_product_title%22
    

    It will works for you ...