Skip to content

Commit

Permalink
Feat taxref/search: add parameter "fields"
Browse files Browse the repository at this point in the history
Use query string parameter "fields" to add taxref fields into the
response body.
Fields must be separate by comma.
Improve documentation for /taxref/search webservice.

Close #243.
  • Loading branch information
jpm-cbna authored and amandine-sahl committed Jun 10, 2021
1 parent a460877 commit c78a197
Show file tree
Hide file tree
Showing 16 changed files with 635 additions and 12 deletions.
43 changes: 31 additions & 12 deletions apptax/taxonomie/routestaxref.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,27 @@ def getTaxrefBibtaxonList():

@adresses.route("/search/<field>/<ilike>", methods=["GET"])
def getSearchInField(field, ilike):
"""
Get the first 20 result of Taxref table for a given field with an ilike query
Use trigram algo to add relevance
:params field: a Taxref column
:type field: str
:param ilike: the ilike where expression to filter
:type ilike:str
:query str add_rank: join on table BibTaxrefRank and add the column 'nom_rang' to the result
:query str rank_limit: return only the taxon where rank <= of the given rank (id_rang of BibTaxrefRang table)
:returns: Array of dict
""".. http:get:: /taxref/search/(str:field)/(str:ilike)
.. :quickref: Taxref;
Retourne les 20 premiers résultat de la table "taxref" pour une
requête sur le champ `field` avec ILIKE et la valeur `ilike` fournie.
L'algorithme Trigramme est utilisé pour établir la correspondance.
:query fields: Permet de récupérer des champs suplémentaire de la
table "taxref" dans la réponse. Séparer les noms des champs par
des virgules.
:query is_inbibnom: Ajoute une jointure sur la table "bib_noms".
:query add_rank: Ajoute une jointure sur la table "bib_taxref_rangs"
et la colonne nom_rang aux résultats.
:query rank_limit: Retourne seulement les taxons dont le rang est
supérieur ou égal au rang donné. Le rang passé doit être une
valeur de la colonne "id_rang" de la table "bib_taxref_rangs".
:statuscode 200: Tableau de dictionnaires correspondant aux résultats
de la recherche dans la table "taxref".
:statuscode 500: Aucun rang ne correspond à la valeur fournie.
Aucune colonne ne correspond à la valeur fournie.
"""
taxrefColumns = Taxref.__table__.columns
if field in taxrefColumns:
Expand All @@ -73,6 +82,16 @@ def getSearchInField(field, ilike):
.order_by(desc("idx_trgm"))
)

if request.args.get("fields"):
fields = request.args["fields"].split(",")
for field in fields:
if field in taxrefColumns:
column = taxrefColumns[field]
q = q.add_columns(column)
else:
msg = f"No column found in Taxref for {field}"
return jsonify(msg), 500

if request.args.get("is_inbibnoms"):
q = q.join(BibNoms, BibNoms.cd_nom == Taxref.cd_nom)
join_on_bib_rang = False
Expand Down
20 changes: 20 additions & 0 deletions docs/api/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
35 changes: 35 additions & 0 deletions docs/api/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
29 changes: 29 additions & 0 deletions docs/api/source/apptax.log.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apptax.log package
==================

Submodules
----------

apptax.log.logmanager module
----------------------------

.. automodule:: apptax.log.logmanager
:members:
:undoc-members:
:show-inheritance:

apptax.log.models module
------------------------

.. automodule:: apptax.log.models
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: apptax.log
:members:
:undoc-members:
:show-inheritance:
39 changes: 39 additions & 0 deletions docs/api/source/apptax.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apptax package
==============

Subpackages
-----------

.. toctree::
:maxdepth: 4

apptax.log
apptax.taxonomie
apptax.utils

Submodules
----------

apptax.database module
----------------------

.. automodule:: apptax.database
:members:
:undoc-members:
:show-inheritance:

apptax.index module
-------------------

.. automodule:: apptax.index
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: apptax
:members:
:undoc-members:
:show-inheritance:
77 changes: 77 additions & 0 deletions docs/api/source/apptax.taxonomie.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
apptax.taxonomie package
========================

Submodules
----------

apptax.taxonomie.filemanager module
-----------------------------------

.. automodule:: apptax.taxonomie.filemanager
:members:
:undoc-members:
:show-inheritance:

apptax.taxonomie.models module
------------------------------

.. automodule:: apptax.taxonomie.models
:members:
:undoc-members:
:show-inheritance:

apptax.taxonomie.routesbibattributs module
------------------------------------------

.. automodule:: apptax.taxonomie.routesbibattributs
:members:
:undoc-members:
:show-inheritance:

apptax.taxonomie.routesbiblistes module
---------------------------------------

.. automodule:: apptax.taxonomie.routesbiblistes
:members:
:undoc-members:
:show-inheritance:

apptax.taxonomie.routesbibnoms module
-------------------------------------

.. automodule:: apptax.taxonomie.routesbibnoms
:members:
:undoc-members:
:show-inheritance:

apptax.taxonomie.routesbibtypesmedia module
-------------------------------------------

.. automodule:: apptax.taxonomie.routesbibtypesmedia
:members:
:undoc-members:
:show-inheritance:

apptax.taxonomie.routestaxref module
------------------------------------

.. automodule:: apptax.taxonomie.routestaxref
:members:
:undoc-members:
:show-inheritance:

apptax.taxonomie.routestmedias module
-------------------------------------

.. automodule:: apptax.taxonomie.routestmedias
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: apptax.taxonomie
:members:
:undoc-members:
:show-inheritance:
45 changes: 45 additions & 0 deletions docs/api/source/apptax.utils.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apptax.utils package
====================

Submodules
----------

apptax.utils.genericfunctions module
------------------------------------

.. automodule:: apptax.utils.genericfunctions
:members:
:undoc-members:
:show-inheritance:

apptax.utils.genericmodels module
---------------------------------

.. automodule:: apptax.utils.genericmodels
:members:
:undoc-members:
:show-inheritance:

apptax.utils.routesconfig module
--------------------------------

.. automodule:: apptax.utils.routesconfig
:members:
:undoc-members:
:show-inheritance:

apptax.utils.utilssqlalchemy module
-----------------------------------

.. automodule:: apptax.utils.utilssqlalchemy
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: apptax.utils
:members:
:undoc-members:
:show-inheritance:
67 changes: 67 additions & 0 deletions docs/api/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('../../..'))


# -- Project information -----------------------------------------------------

project = 'TaxHub'
copyright = '2020, GeoNature contributors'
author = 'GeoNature contributors'

# The full version, including alpha/beta/rc tags
release = '1.7.4.dev0'


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.viewcode",
"sphinxcontrib.httpdomain",
"sphinxcontrib.autohttp.flask",
"sphinxcontrib.autohttp.flaskqref",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
20 changes: 20 additions & 0 deletions docs/api/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.. TaxHub documentation master file, created by
sphinx-quickstart on Tue Oct 6 15:43:23 2020.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to TaxHub's documentation!
==================================

.. toctree::
:maxdepth: 2
:caption: Contents:



Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
Loading

0 comments on commit c78a197

Please sign in to comment.