[CKAN-support] How to store custom value in the same way tags are stored - Got it!!!!

Nigel Babu nigel.babu at okfn.org
Mon Apr 7 03:00:03 UTC 2014


Cheers, glad you got it working.

Nigel Babu

Developer  |  @nigelbabu <https://twitter.com/nigelbabu>

The Open Knowledge Foundation <http://okfn.org/>

Empowering through Open Knowledge

http://okfn.org/  |  @okfn <http://twitter.com/OKFN>  |  OKF on
Facebook<https://www.facebook.com/OKFNetwork> |
Blog <http://blog.okfn.org/>  |  Newsletter<http://okfn.org/about/newsletter>

 CKAN | http://ckan.org/ | @CKANproject
<http://twitter.com/CKANproject> |the world’s leading open-source data
portal platform


On 6 April 2014 15:02, Carlos Quiros <cquiros at qlands.com> wrote:

>
> Ha! I cracked it!!! The facet must be on the vocabulary and not on the
> field itself. I got this from the Solr schema.xml where vocab is defined
>
> <dynamicField name="vocab_*" type="string" indexed="true" stored="true"
> *multiValued="true"*/>
>
> So I changed my facet to:
>
> def dataset_facets(self,facets_dict, package_type):
>         facets_dict['*vocab_*ILRI_prjregions'] = 'Regions'
>         return facets_dict
>
> And it worked!!!
>
> Carlos.
>
> On 04/06/2014 12:05 PM, Carlos Quiros wrote:
>
> Hi Nigel,
>
> Just to add to my previous email.
>
> I removed all datasets and created a new one with two regions: "EAST ASIA"
> and "WEST AFRICA". A Call to the API shows properly the values:
>
> ILRI_prjregions": [
>
>     "EAST ASIA",
>     "WEST AFRICA"
>
> ],
>
> But the facet on ILRI_prjregions returns blank ("There are no Regions that
> match this search"). A facet on any other custom field works because such
> field stores one value. So the questions is: How can I create a facet on a
> custom field that is multi-value? Just like the Facet on Tags?
>
> Thanks,
> Carlos.
>
> On 04/05/2014 09:59 PM, Carlos Quiros wrote:
>
> Hi Nigel,
>
> The main idea of storing countries as a vocabulary and using covert
> from/to tags was to enable a facet on countries so users would have been
> able to see how many datasets are per country or search by country
> (clicking in the facet item).
>
> After exploring how convert_from/to_tags worked I managed to store the
> regions in Tags . See this paste bin (http://pastebin.com/7thzE0Ja).
> Basically I had to implement a custom convertToTags() very similar to the
> one in CKAN converters.py
>
> Now I can see in the API the regions as two separated items out from
> convertFromTags:
>
> ...
> ILRI_prjregions": [
>
>     "WEST AFRICA",
>     "EAST AFRICA"
>
> ],
> tags": [
>
>     {
>         "vocabulary_id": null,
>         "display_name": "environment",
>         "name": "environment",
>         "revision_timestamp": "2014-03-11T09:17:21.728266",
>         "state": "active",
>         "id": "95c5c43f-8417-4126-b74a-584e87781b55"
>     },
>     {
>         "vocabulary_id": null,
>         "display_name": "fish",
>         "name": "fish",
>         "revision_timestamp": "2014-03-10T08:11:51.184357",
>         "state": "active",
>         "id": "5e429d14-7634-45ac-8f72-21a4ba1117a2"
>     },
>     {
>         "vocabulary_id": null,
>         "display_name": "livstock",
>         "name": "livstock",
>         "revision_timestamp": "2014-03-10T08:11:51.184357",
>         "state": "active",
>         "id": "30d05056-3ae8-45e3-b4cb-c37a19fe9003"
>     }
>
> ],
> .....
>
> I created the new facet on the regions with
>
> def dataset_facets(self,facets_dict, package_type):
>         facets_dict['ILRI_prjregions'] = 'Regions'
>         return facets_dict
>
> I can see the new facet in CKAN but h.get_facet_items_dict used in
> /templates/snippets/facet_list.html only returns one value ("WEST AFRICA").
>
> Any idea what could be happening? My guess is that ILRI_prjregions should
> be a dict but of which structure?
>
> Thanks,
> Carlos.
>
> On 04/03/2014 07:18 PM, Nigel Babu wrote:
>
> Hi Carlos,
>
> Sorry about the delay in getting back to you. We've just changed how we
> deal with support requests so that we can track them better. This one seems
> to have fallen through the cracks. I'm not entirely sure of the answer to
> this one, so I'll get back to you within a day or two after I've confirmed
> with my colleagues.
>
>
>
>  Nigel Babu
>
> Developer  |  @nigelbabu <https://twitter.com/nigelbabu>
>
> The Open Knowledge Foundation <http://okfn.org/>
>
> Empowering through Open Knowledge
>
> http://okfn.org/  |  @okfn <http://twitter.com/OKFN>  |  OKF on Facebook<https://www.facebook.com/OKFNetwork> |
> Blog <http://blog.okfn.org/>  |  Newsletter<http://okfn.org/about/newsletter>
>
>   CKAN | http://ckan.org/ | @CKANproject <http://twitter.com/CKANproject>|the world’s leading open-source data portal platform
>
>
> On 2 April 2014 19:41, Carlos Quiros <cquiros at qlands.com> wrote:
>
>>  Hi Nigel,
>>
>> Sorry to write directly to you but I haven receive any answer to my
>> question.
>>
>> Carlos.
>>
>>
>> On 03/25/2014 01:00 PM, Carlos Quiros wrote:
>>
>> I'm still waiting for an answer.
>>
>> I created a new vocabulary for my countries and used "convert_to_tags",
>> "convert_from_tags" but because the data in the form is coma separated the
>> "convert_to_tags" returns "is not JSON serializable".
>>
>> Again how should I convert the coma separated string so it is stored
>> properly in tags?
>>
>> Thanks,
>> Carlos.
>>
>> On 03/21/2014 05:49 PM, Carlos Quiros wrote:
>>
>> Hi,
>>
>> I would like to store "Regions" in the same way Tags are stored so I can
>> use it in IFacets. Currently I am storing it as a value separated by coma
>> using:
>>
>> def _add_custom_metadata_to_schema(self, schema):
>>   schema.update({'ILRI_actyregions':
>> [toolkit.get_validator('ignore_missing'),toolkit.get_converter('convert_to_extras')]})
>>
>> But if I use it like that (coma separated) IFacets show for example
>> "Kenya,Tanzania" and not Kenya and Tanzania separated.
>>
>> So I guess I need to store Regions in the same way Tags are stored. How
>> can I do this?
>>
>> Thanks,
>> Carlos
>>
>>
>>
>>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.okfn.org/mailman/private/ckan-support/attachments/20140407/1937c609/attachment-0002.html>


More information about the ckan-support mailing list