Search code examples
solrquotessolrnet

SolrNet - How to disable quotes in SolrQueryByField?


I am using SolrQueryByField to test how Solr performs when searching particular fields. However SolrQueryByField seems to apply quotes around multi-word query. The final url has something like.. select?q=(prodname:"champion+creatine") ... This try to do an exact match. Is there a way to disable quotes in SolrQueryByField so that it translates into .. select?q=(prodname:champion+creatine). Thanks!


Solution

  • You can do the following in SolrNet:

    var q = new SolrQuery("prodname:champion") && new SolrQuery("prodname:creatine");
    var response = solr.Query(q);
    

    Which will produce:

     select?q=prodname:champion+prodname:creatine
    

    This should accomplish what you want. If not, please reference the SolrNet - Querying page for more options. Also, I believe the reason you are seeing the behavior described in your question is because SolrQueryByField performs special character escaping.

    Edit: Using fix for SolrQueryByField mentioned in comment. (Make sure you have a version of SolrNet that supports this…

     var q = new SolrQueryByField("prodname", "champion creatine") { Quoted = false };