projectblacklight / blacklight

Blacklight provides a discovery interface for any Solr (http://lucene.apache.org/solr) index.
http://projectblacklight.org/
Other
757 stars 256 forks source link

When using JSON Query DSL, requests with a search_field param but no q param causes an error #3067

Closed sandbergja closed 11 months ago

sandbergja commented 11 months ago

Steps to recreate

  1. Create a local development environment running Solr 7 or 8, and with a solrconfig.xml that specifies a luceneMatchVersion of 7.1 or lower.

  2. Confirm that you can access http://localhost:3000/?search_field=title, and that it returns all titles in your solr.

  3. Configure your title field to use the JSON Query DSL in the catalog controller (using the clause_params configuration option). For example:

    config.add_search_field('title') do |field|
      field.solr_parameters = {
        'spellcheck.dictionary': 'title',
        qf: '${title_qf}',
        pf: '${title_pf}'
      }
      field.clause_params = { edismax: field.solr_parameters.dup }
    end
  4. Restart your rails server

  5. Note that http://localhost:3000/?search_field=title now returns an error:


RSolr::Error::Http - 400 Bad Request
Error: Error when parsing json query, expect a json object here, but found : null
URI: http://127.0.0.1:8983/solr/blacklight-core/advanced?wt=json
Request Headers: {"Content-Type"=>"application/json"}
Request Data: "{\"params\":{\"qt\":null,\"rows\":10,\"spellcheck.dictionary\":\"title\",\"qf\":\"${title_qf}\",\"pf\":\"${title_pf}\",\"facet\":true,\"facet.field\":[\"format\",\"{!ex=pub_date_ssim_single}pub_date_ssim\",\"subject_ssim\",\"language_ssim\",\"lc_1letter_ssim\",\"subject_geo_ssim\",\"subject_era_ssim\"],\"f.subject_ssim.facet.limit\":21,\"f.language_ssim.facet.limit\":11,\"facet.pivot\":[\"format,language_ssim\"],\"facet.query\":[\"pub_date_ssim:[2018 TO *]\",\"pub_date_ssim:[2013 TO *]\",\"pub_date_ssim:[1998 TO *]\"],\"sort\":\"score desc, pub_date_si desc, title_si asc\"},\"query\":{\"bool\":{\"must\":[{\"edismax\":{\"spellcheck.dictionary\":\"title\",\"qf\":\"${title_qf}\",\"pf\":\"${title_pf}\",\"query\":null}}]}}}"
barmintor commented 11 months ago

Is this also related to https://github.com/projectblacklight/blacklight/pull/3057 ?

sandbergja commented 11 months ago

Oh, it totally is! Thanks for catching that. Closing this as duplicate of #3048