An extension that utilizes Solr Suggest component to provide auto-suggest feature in CKAN's main dataset search.
Compatibility with core CKAN versions:
CKAN version | Compatible? |
---|---|
2.6 and earlier | not tested |
2.7 | not tested |
2.8 | not tested |
2.9 | yes |
To install ckanext-suggest:
- In order to enable SOLR suggest component you need to edit solrconfig.xml in your application's SOLR core settings and add the following snippet in the components section:
<!-- Suggester Component
The SuggestComponent in Solr provides users
with automatic suggestions for query terms.
-->
<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">datasetTitleSuggester</str>
<str name="lookupImpl">AnalyzingInfixLookupFactory</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="field">title</str>
<str name="minPrefixChars">2</str>
<str name="suggestAnalyzerFieldType">text</str>
<str name="buildOnStartup">false</str>
<str name="highlight">false</str>
</lst>
<lst name="suggester">
<str name="name">datasetNotesSuggester</str>
<str name="lookupImpl">AnalyzingInfixLookupFactory</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="field">notes</str>
<str name="minPrefixChars">2</str>
<str name="suggestAnalyzerFieldType">text</str>
<str name="buildOnStartup">false</str>
<str name="highlight">false</str>
</lst>
<lst name="suggester">
<str name="name">datasetTagsSuggester</str>
<str name="lookupImpl">FuzzyLookupFactory</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="field">tags</str>
<str name="suggestAnalyzerFieldType">text</str>
<str name="buildOnStartup">false</str>
</lst>
</searchComponent>
<!-- A request handler for demonstrating the suggest component.
-->
<requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="suggest">true</str>
<str name="suggest.count">5</str>
<str name="suggest.dictionary">datasetTitleSuggester</str>
<str name="suggest.dictionary">datasetNotesSuggester</str>
<str name="suggest.dictionary">datasetTagsSuggester</str>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>
- Restart SOLR:
sudo service solr restart
- Activate your CKAN virtual environment, for example:
. /usr/lib/ckan/default/bin/activate
- Clone the source and install it on the virtualenv
git clone https://github.com/keitaroinc/ckanext-suggest.git
cd ckanext-suggest
pip install -e .
pip install -r requirements.txt
-
Add
suggest
to theckan.plugins
setting in your CKAN config file (by default the config file is located at/etc/ckan/default/ckan.ini
). -
Restart CKAN. For example if you've deployed CKAN with Apache on Ubuntu:
sudo service apache2 reload
- Build the lookup data structure in SOLR:
ckan -c /etc/ckan/default/ckan.ini suggest buid
- Set up a CRON job that will update the lookup data structure on regular basis, for example:
@daily ckan -c /etc/ckan/default/ckan.ini suggest buid
None at the moment.
To install ckanext-suggest for development, activate your CKAN virtualenv and do:
git clone https://github.com/keitaroinc/ckanext-suggest.git
cd ckanext-suggest
python setup.py develop
pip install -r dev-requirements.txt
To run the tests, do:
pytest --ckan-ini=test.ini
If ckanext-suggest should be available on PyPI you can follow these steps to publish a new version:
-
Update the version number in the
setup.py
file. See PEP 440 for how to choose version numbers. -
Make sure you have the latest version of necessary packages:
pip install --upgrade setuptools wheel twine
-
Create a source and binary distributions of the new version:
python setup.py sdist bdist_wheel && twine check dist/*
Fix any errors you get.
-
Upload the source distribution to PyPI:
twine upload dist/*
-
Commit any outstanding changes:
git commit -a git push
-
Tag the new release of the project on GitHub with the version number from the
setup.py
file. For example if the version number insetup.py
is 0.0.1 then do:git tag 0.0.1 git push --tags