OpenDataGIS / ckanext-facet_scheming

Ckan extension to facet based in fields defined in the scheming extension
GNU Affero General Public License v3.0
0 stars 3 forks source link

ckanext-facet_scheming

ckanext-facet_scheming provides functions and templates that have been specially developed to extend the search functionality in CKAN for custom schemas. It uses the fields defined in a scheming file to provide a set of tools to use these fields for scheming, and a way to include icons in their labels when displaying them.

image

Requirements

Warning
This extension needs custom GeoDCAT-AP ckanext-scheming extension to work.

facet_scheming is designed to provide templates and functions to be used by other extensions over it. It uses the fields defined in a scheming file to provide a set of tools to use those fields for scheming, and a way to include icons in its labels when displaying them.

Compatibility with core CKAN versions:

CKAN version Compatible?
2.8 and earlier not tested
2.9 yes
2.10 not yet

Suggested values:

Installation

To install ckanext-facet_scheming:

  1. Activate your CKAN virtual environment, for example:

    . /usr/lib/ckan/default/bin/activate

  2. Clone the source and install it on the virtualenv

    git clone https://github.com/dsanjurj/ckanext-facet_scheming.git
    cd ckanext-facet_scheming
    pip install -e .
    pip install -r requirements.txt
  3. Add facet_scheming to the ckan.plugins setting in your CKAN config file (by default the config file is located at /etc/ckan/default/ckan.ini).

  4. Clear the index in solr:

    ckan -c [route to your .ini ckan config file] search-index clear

  5. Modify the schema file on Solr (schema or managed schema) to add the multivalued fields added in the scheming extension used for faceting. You can add any field defined in the schema file used in the ckanext-scheming extension that you want to use for faceting. You must define each field with these parameters:

    • type: string - to avoid split the text in tokens, each individually "faceted".
    • uninvertible: false - as recomended by solr´s documentation
    • docValues: true - to ease recovering faceted resources
    • indexed: true - to let ckan recover resources under this facet
    • stored: true - to let the value to be recovered by queries
    • multiValued: well... it depends on if it is a multivalued field (several values for one resource) or a regular field (just one value). Use "true" or "false" respectively.

    By now iepnb extension are ready to use these multivalued fields. You have to add this configuration fragment to solr schema in order to use them:

    <!-- IEPNB extra fields -->
      <field name="tag_uri" type="string" uninvertible="false" docValues="true" indexed="true" stored="true" multiValued="true"/>
      <field name="conforms_to" type="string" uninvertible="false" docValues="true" indexed="true" stored="true" multiValued="true"/>
      <field name="lineage_source" type="string" uninvertible="false" docValues="true" indexed="true" stored="true" multiValued="true"/>
      <field name="lineage_process_steps" type="string" uninvertible="false" docValues="true" indexed="true" stored="true" multiValued="true"/>
      <field name="reference" type="string" uninvertible="false" docValues="true" indexed="true" stored="true" multiValued="true"/>
      <field name="theme" type="string" uninvertible="false" docValues="true" indexed="true" stored="true" multiValued="true"/>
      <field name="theme_es" type="string" uninvertible="false" docValues="true" multiValued="true" indexed="true" stored="true"/>
      <field name="metadata_profile" type="string" uninvertible="false" docValues="true" multiValued="true" indexed="true" stored="true"/>
      <field name="resource_relation" type="string" uninvertible="false" docValues="true" indexed="true" stored="true" multiValued="true"/>

    Note
    You can ommit any field you're not going to use for faceting, but the best policy could be to add all values at the beginning.

    Be sure to restart Solr after modify the schema.

  6. Restart CKAN. For example if you've deployed CKAN with Apache on Ubuntu:

    sudo service apache2 reload

  7. Reindex solr index:

    ckan -c [route to your .ini ckan config file] search-index rebuild

    Sometimes solr can issue an error while reindexing. In that case I'd try to restart solr, delete index ("search-index clear"), restart solr, rebuild index, and restart solr again.

    Ckan needs to "fix" multivalued fields to be able to recover values correctly for faceting, so this step must be done in order to use faceting with multivalued fields.

Helpers

facet_scheming provides a set of useful helpers to be used in templates

Templates

Also a set of useful templates and snippets are provided

Config settings

Config (.ini) file

There are not mandatory sets in the config file for this extension. You can use the following sets:

  facet_scheming.facet_list: [list of fields]      # List of fields in scheming file to use to faceting. Use ckan defaults if not provided.
  facet_scheming.default_facet_operator: [AND|OR]  # OR if not defined
  facet_scheming.icons_dir: (dir)                  # images/icons if not defined

As an example for facet list, we could suggest:

  facet_scheming.facet_list = "theme groups theme_es dcat_type owner_org res_format publisher_name publisher_type frequency tags tag_uri conforms_to spatial_uri"

The same custom fields for faceting can be used when browsing organizations and groups data:

  facet_scheming.organization_custom_facets = true
  facet_scheming.group_custom_facets = true

This two last settings are not mandatory. You can omit one or both (or set them to 'false'), and the default fields for faceting will be used instead.

Icons

Icons' location for each field option in the scheming file can be set in multiple ways:

Having the root path for the icons used by the values for the options of a field, you must define where the icons for each option must be, or know where the extension will search for them by default

Icons files are tested for existence when using fscheming_schema_icon function to get them. If the file doesn't exist, the function returns None. Icons can be provided by any ckan extension, in its public directory.

You can set a default icon for a field using the default_icon setting in the scheming file. You can get it using fscheming_schema_get_default_icon function, and is your duty do decide when and where get and use it in a template.

Examples:

We have set facet\_scheming.icons\_dir: images/icons in .ini CKAN config file (or not set this parameter at all, because this is the default value)

Defining icons in a schema file:

  - field_name: strange_field
  ...
    icons_dir: icons/for/strange/field
  ...
    choices:
    - value: http://some_domain.fake/level1/level2/strange_value
      label:
        en: Strange Value
        es: Valor Extraño
      description:
        en: ''
        es: 'Valor extraño para un campo extraño'
      icon: strange_value_icon.gif
      ...

Icons file for "strange_field" field will be searched in public/icons/for/strange/field directory in all CKAN extensions. Url will be icons/for/strange/field/strange_value_icon.gif if file was found in any extension.

The value provided in facet_scheming.icons_dir (images/icons) will NOT be used to compose the url, because you have provided icons_dir in the scheming file for this field.

Using icons not defined in the schema file:

  - field_name: strange_field
  ...
    choices:
    - value: http://some_domain.fake/level1/level2/strange_value
      label:
        en: Strange Value
        es: Valor Extraño
      description:
        en: ''
        es: 'Valor extraño para un campo extraño'
      ...

Directory for icons will be taken from facet_scheming.icons_dir, bacause you not provide a

Directory for icons will be taken from facet_scheming.icons_dir, bacause you not provide a

Url for this option will be images/icons/strange_field/level2/strange_value.[ext], beeing [ext] any extension in svg, png, jpg or gif (searched in this order).

Developer installation

To install ckanext-facet_scheming for development, activate your CKAN virtualenv and do:

git clone https://github.com/dsanjurj/ckanext-facet_scheming.git
cd ckanext-facet_scheming
python setup.py develop
pip install -r dev-requirements.txt

Tests

To run the tests, do:

pytest --ckan-ini=test.ini

Releasing a new version of ckanext-facet_scheming

If ckanext-facet_scheming should be available on PyPI you can follow these steps to publish a new version:

  1. Update the version number in the setup.py file. See PEP 440 for how to choose version numbers.

  2. Make sure you have the latest version of necessary packages:

    pip install --upgrade setuptools wheel twine

  3. Create a source and binary distributions of the new version:

    python setup.py sdist bdist_wheel && twine check dist/*

    Fix any errors you get.

  4. Upload the source distribution to PyPI:

    twine upload dist/*

  5. Commit any outstanding changes:

    git commit -a git push

  6. Tag the new release of the project on GitHub with the version number from the setup.py file. For example if the version number in setup.py is 0.0.1 then do:

    git tag 0.0.1 git push --tags

License

AGPL