[ckan-dev] change search from OR to AND (hotz)

hotz hotz at informatik.uni-hamburg.de
Fri Aug 22 06:12:43 UTC 2014


to achieve "AND" behavior we (=Fabian) extent:
/ckan/lib/default/src/ckan/ckan/controllers/package.py

in our plugin and put:
data_dict = {
                 'q': q,
                 'fq': fq.strip(),
                 'facet.field': facets.keys(),
                 'rows': limit,
                 'start': (page - 1) * limit,
                 'sort': sort_by,
                 'extras': search_extras,
                 # To get the real AND search
                 'mm': '100%'
             }

The default for 'mm' is in (if I'm right) (ckan 2.1.2):
ckan/lib/default/src/ckan/ckan/lib/search/query.py

and says:
query['mm'] = query.get('mm', '2<-1 5<80%')

which is "AND" if you use two search words and which is "nearly AND" if 
you use more
search words (see SOLR/Lucene documentation). This would explain the 
results reported in the other posts.

best wishes,
lothar


Am 21.08.2014 02:42, schrieb James Gagan:
> Looks like "+" and "-" operators work too. But, we had a requirement
> to make it always an AND without having to type in operators. Hence
> the extra coding.
>
> cheers,
> James
>
>
> On Wed, Aug 20, 2014 at 4:21 PM, Aaron McGlinchy
> <McGlinchyA at landcareresearch.co.nz> wrote:
>> Our install of CKAN (v2.2) seems to search AND by default, but I can actually specify operator such as OR or AND in my search text and it refines the result accordingly.
>>
>> e.g. I have 8 datasets that have the tag Flora, and of them 6 also have the tag Moss.
>>
>> A search for    moss flora   returns 6 results (= moss and flora)
>>                  moss or flora    returns 8 results
>>                  "moss or flora" = zero results (no datasets have the exact tag/text "moss or flora"
>>
>> So you can use the normal sorts of formatting/operators in the search box (just as in google) to fine tune the search, no special coding required (at least on v2.2)
>>
>> Cheers
>> Aaron
>>
>> ________________________________
>>
>> Please consider the environment before printing this email
>> Warning: This electronic message together with any attachments is confidential. If you receive it in error: (i) you must not read, use, disclose, copy or retain it; (ii) please contact the sender immediately by reply email and then delete the emails.
>> The views expressed in this email may not be those of Landcare Research New Zealand Limited. http://www.landcareresearch.co.nz
>> _______________________________________________
>> ckan-dev mailing list
>> ckan-dev at lists.okfn.org
>> https://lists.okfn.org/mailman/listinfo/ckan-dev
>> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>
>






More information about the ckan-dev mailing list