[ckan-dev] Custom Search Facets

Adrià Mercader adria.mercader at okfn.org
Wed Oct 29 09:55:01 UTC 2014


Hi Renato and Rachel,

I think there is some confusion about the fields that you should use
for faceting

> facets_dict['extras_level'] = p.toolkit._('Level')

> It's enough to use the key 'extras_level' to tell CKAN to get the facet from the extras. The right-hand side is the name of the facet.

When a dataset dict is indexed in Solr, all extra fields are indexed
to allow searching and faceting. For each extra, two fields are
indexed in Solr. Taking your extra 'level' as example:

* The field 'level' will be indexed as 'string'. This basically
indexes the value "as is" and is the one that should be used for
faceting and sorting
* The field 'extra_level' will be indexed as 'text'. This is a more
complex field type that is basically optimized for searching (eg
different words or parts will be tokenized, which might be what is
happening to 'sparql-language')

@Renato, if you are storing 'queryLanguage' as an extra, try using
'queryLanguage' when defining your facets instead of
'extra_queryLanguage' to see if you get the proper values.

If you are storing the values as tags with a vocabulary, try using
'vocab_queryLanguage'. Apparently these are also indexed, but I'm not
familiar with how they work.

It's pretty clear that we could use some docs in this front...

Hope this helps,

Adrià


On 28 October 2014 19:27, Renato Guevara <guevara.renato at gmail.com> wrote:
> One of the issues I have is the following:
>
> I have a plugin that is adding new custom fields.
>
> class DescribeFieldsPlugin(p.SingletonPlugin, tk.DefaultDatasetForm):
>         p.implements(p.IDatasetForm)
>         p.implements(p.IConfigurer)
>         p.implements(p.ITemplateHelpers)
>
>         def get_helpers(self):
>                 return {'queryLanguages': queryLanguages}
>
>         def _modify_package_schema(self, schema):
>                 '''
>                 schema.update({
>                         'queryLanguage':
> [tk.get_validator('ignore_missing'),
>
> tk.get_converter('convert_to_extras')]
>                 })
>                 '''
>                 schema.update({
>                         'queryLanguage':
> [tk.get_validator('ignore_missing'),
>
> tk.get_converter('convert_to_tags')('queryLanguages')]
>                 })
>                 return schema
>
>         def create_package_schema(self):
>                 schema = super(DescribeFieldsPlugin,
> self).create_package_schema()
>                 schema = self._modify_package_schema(schema)
>                 return schema
>
>         def update_package_schema(self):
>                 schema = super(DescribeFieldsPlugin,
> self).update_package_schema()
>                 schema = self._modify_package_schema(schema)
>                 return schema
>
>         def show_package_schema(self):
>                 schema = super(DescribeFieldsPlugin,
> self).show_package_schema()
>                 '''
>                 schema.update({
>                         'queryLanguage':
> [tk.get_converter('convert_from_extras'),
>
> tk.get_validator('ignore_missing')]
>                 })
>                 '''
>
> schema['tags']['__extras'].append(tk.get_converter('free_tags_only'))
>                 schema.update({
>                         'queryLanguage': [
>
> tk.get_converter('convert_from_tags')('queryLanguages'),
>                         tk.get_validator('ignore_missing')]
>                 })
>                 return schema
>
> def create_queryLanguages():
>         user = tk.get_action('get_site_user')({'ignore_auth': True}, {})
>         context = {'user': user['name']}
>         try:
>                 data = {'id': 'queryLanguages'}
>                 tk.get_action('vocabulary_show')(context, data)
>         except tk.ObjectNotFound:
>                 data = {'name': 'queryLanguages'}
>                 vocab = tk.get_action('vocabulary_create')(context, data)
>                 for tag in (u'sparql-language',u'sql'):
>                         data = {'name': tag, 'vocabulary_id': vocab['id']}
>                         tk.get_action('tag_create')(context, data)
>
> def queryLanguages():
>         create_queryLanguages()
>         try:
>                 tag_list = tk.get_action('tag_list')
>                 queryLanguages = tag_list(data_dict={'vocabulary_id':
> 'queryLanguages'})
>                 return queryLanguages
>         except tk.ObjectNotFound:
>                 return None
>
>
> However, when I add a facet for queryLanguage, should I add it as an extra?
> Because what is happening is that the term "sparql-language' is getting
> broken up into two different facets.  Do you know why this may be happening?
>
> On Tue, Oct 28, 2014 at 4:19 AM, Rachel Knowler <rachel.knowler at liip.ch>
> wrote:
>>
>> Sorry, I should have mentioned this in my reply because it's not covered
>> well in the docs. The new facet that I added is called 'Level'. It's added
>> to all my datasets as an extra field, during harvesting. In this line, I add
>> it to the facets_dict:
>>
>> facets_dict['extras_level'] = p.toolkit._('Level')
>>
>> It's enough to use the key 'extras_level' to tell CKAN to get the facet
>> from the extras. The right-hand side is the name of the facet.
>>
>> Best,
>> Rachel
>>
>>
>>
>>
>> On 28.10.2014 09:12, Rachel Knowler wrote:
>>
>> Hi Renato,
>>
>> To add a custom facet search you have to implement the iFacets interface
>> in your plugin. This is described in the documentation here:
>> http://docs.ckan.org/en/latest/extensions/plugin-interfaces.html#ckan.plugins.interfaces.IFacets.
>> I recently did this and you can see my code for it here:
>> https://github.com/openresearchdata/ckanext-ord-hierarchy/blob/master/ckanext/ord_hierarchy/plugin.py#L210.
>>
>> Hope that helps!
>>
>> - Rachel
>>
>> On 27.10.2014 16:02, Renato Guevara wrote:
>>
>> I was able to successfully add a custom field to my dataset.  In fact, it
>> was a vocabulary with its corresponding tags.  However, now, I'm looking
>> into adding a custom facet search for this specific custom field.  In this
>> case, the name of my custom field is queryLanguage.  I looked through the
>> forum and documentation to see if there were any tutorials but I couldn't
>> find any.  Would someone be able to point me in the right direction.  Again,
>> I'm trying to add a custom facet search like there is on the default Dataset
>> search page on the left side.  Right now, the default ones are "Publishers",
>> "Subjects", "Organizations", "Groups", "Tags", "Formats", and "Licenses".
>> I'd like to add "Query Languages".
>>
>> Thanks,
>>
>> Renato Guevara
>>
>>
>> _______________________________________________
>> 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
>>
>>
>> --
>> Liip AG // Limmatstrasse 183 // CH-8005 Zürich
>> Tel +41 43 500 39 80 // Mob +41 78 658 26 12 // www.liip.ch
>>
>>
>> --
>> Liip AG // Limmatstrasse 183 // CH-8005 Zürich
>> Tel +41 43 500 39 80 // Mob +41 78 658 26 12 // www.liip.ch
>>
>>
>> _______________________________________________
>> 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
>>
>
>
> _______________________________________________
> 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