Repository: ckan/ckan

Issue:
Quirks with Solr6
Some quirks with CKAN and up-to-date versions of Solr:

- default field in the schema is deprecated: `[ckan] default search field in schema is text. WARNING: Deprecated,&#8203; please use 'df' on request instead.`
- When multiple terms are provided (like an org filter) the field name to search must be explicit. This is currently breaking searching for terms within an organization (`q=test +owner_org:...` fails, `q=text:test +owner_org:...` works, `q=test` works).
- While we're here, owner org should be a filter not part of the query.


Discussion:
For point 2, a very small change should be forward and backwards compatible and safe for back-porting. Ex:

```diff
diff --git a/ckan/controllers/group.py b/ckan/controllers/group.py
index 087209f..912c402 100644
--- a/ckan/controllers/group.py
+++ b/ckan/controllers/group.py
@@ -236,6 +236,9 @@ class GroupController(base.BaseController):
                    'for_view': True, 'extras_as_string': True}

         q = c.q = request.params.get('q', '')
+        if q is not None and q.strip():
+            q = 'text:{q}'.format(q=q)
+
         # Search within group
         if c.group_dict.get('is_organization'):
             q += ' owner_org:"%s"' % c.group_dict.get('id')
```
Is solR 6.0.0 supported with CKAN 2.7.2 ?

I'm getting this error:

>  [Reason: sort param field can't be found: metadata_modified] [Tue Apr
> 03 15:56:11.881767 2018] [:error] [pid 10485] 2018-04-03 15:56:11,881
> ERROR [ckan.controllers.package] Dataset search error: ('SOLR returned
> an error running query: {\\'sort\\': \\'score desc, metadata_modified
> desc\\', \\'fq\\': [u\\'+dataset_type:dataset\\',
> u\\'+site_id:"default"\\', \\'+state:active\\',
> u\\'+permission_labels:("public")\\'], \\'facet.mincount\\': 1,
> \\'rows\\': 21, \\'facet.field\\': [u\\'organization\\',
> u\\'groups\\', u\\'tags\\', u\\'res_format\\', u\\'license_id\\'],
> \\'facet.limit\\': \\'50\\', \\'facet\\': \\'true\\', \\'q\\':
> \\'*:*\\', \\'start\\': 0, \\'wt\\': \\'json\\', \\'fl\\': \\'id
> validated_data_dict\\'} Error: SolrError(u"Solr responded with an
> error (HTTP 400): [Reason: sort param field can\\'t be found:
> metadata_modified]",)',) [Tue Apr 03 15:56:11.934996 2018] [:error]
> [pid 10485] 2018-04-03 15:56:11,934 INFO  [ckan.lib.base]  /dataset
> render time 0.084 seconds [Tue Apr 03 15:56:12.445289 2018] [:error]
> [pid 10485] 2018-04-03 15:56:12,445 INFO  [ckan.lib.base] 
> /api/i18n/en render time 0.006 seconds

I read in stack overflow to downgrade the solR to v5.0.0.

Resolving patch:
diff --git a/ckan/lib/search/query.py b/ckan/lib/search/query.py
--- a/ckan/lib/search/query.py
+++ b/ckan/lib/search/query.py
@@ -20,7 +20,7 @@
 VALID_SOLR_PARAMETERS = set([
     'q', 'fl', 'fq', 'rows', 'sort', 'start', 'wt', 'qf', 'bf', 'boost',
     'facet', 'facet.mincount', 'facet.limit', 'facet.field',
-    'extras', 'fq_list', 'tie', 'defType', 'mm'
+    'extras', 'fq_list', 'tie', 'defType', 'mm', 'df'
 ])
 
 # for (solr) package searches, this specifies the fields that are searched
diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py
--- a/ckan/logic/action/get.py
+++ b/ckan/logic/action/get.py
@@ -1814,6 +1814,9 @@ def package_search(context, data_dict):
     for key in [key for key in data_dict.keys() if key.startswith('ext_')]:
         data_dict['extras'][key] = data_dict.pop(key)
 
+    # set default search field
+    data_dict['df'] = 'text'
+
     # check if some extension needs to modify the search params
     for item in plugins.PluginImplementations(plugins.IPackageController):
         data_dict = item.before_search(data_dict)


Test patch: