Skip to content

Commit

Permalink
Fix #263 : exact search (#264)
Browse files Browse the repository at this point in the history
* gitignore .DS_Store

* fix #263 : adding `exact` param to use w `search`

* update in documentation for `exact` with `search`

* black formatting

* flake8
  • Loading branch information
pierrotsmnrd authored Mar 16, 2022
1 parent e19227e commit 6232074
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ node_modules
docs/_build

# nix
.direnv
.direnv
**/.DS_Store
16 changes: 12 additions & 4 deletions conda-store-server/conda_store_server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,15 @@ def get_build(db, build_id: int):
return db.query(orm.Build).filter(orm.Build.id == build_id).first()


def get_build_packages(db, build_id: int, search: str = None, build: str = None):
def get_build_packages(
db, build_id: int, search: str = None, exact: bool = False, build: str = None
):
filters = [(orm.build_conda_package.c.build_id == build_id)]
if search:
filters.append(orm.CondaPackage.name.contains(search, autoescape=True))
if exact:
filters.append(orm.CondaPackage.name.like(search.replace("%", r"\%")))
else:
filters.append(orm.CondaPackage.name.contains(search, autoescape=True))
if build:
filters.append(orm.CondaPackage.build.contains(build, autoescape=True))

Expand Down Expand Up @@ -185,10 +190,13 @@ def get_conda_channel(db, channel_name: str):
)


def list_conda_packages(db, search: str = None, build: str = None):
def list_conda_packages(db, search: str = None, exact: bool = False, build: str = None):
filters = []
if search:
filters.append(orm.CondaPackage.name.contains(search, autoescape=True))
if exact:
filters.append(orm.CondaPackage.name.like(search.replace("%", r"\%")))
else:
filters.append(orm.CondaPackage.name.contains(search, autoescape=True))
if build:
filters.append(orm.CondaPackage.build.contains(build, autoescape=True))

Expand Down
10 changes: 8 additions & 2 deletions conda-store-server/conda_store_server/server/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,11 @@ def api_get_build_packages(build_id):
)

search = request.args.get("search")
exact = request.args.get("exact")

build_str = request.args.get("build")
orm_packages = api.get_build_packages(
conda_store.db, build.id, search=search, build=build_str
conda_store.db, build.id, search=search, exact=exact, build=build_str
)
return paginated_api_response(
orm_packages,
Expand Down Expand Up @@ -441,9 +443,13 @@ def api_list_packages():
conda_store = get_conda_store()

search = request.args.get("search")
exact = request.args.get("exact")

build = request.args.get("build")

orm_packages = api.list_conda_packages(conda_store.db, search=search, build=build)
orm_packages = api.list_conda_packages(
conda_store.db, search=search, exact=exact, build=build
)
required_sort_bys, distinct_orm_packages = filter_distinct_on(
orm_packages,
allowed_distinct_ons={
Expand Down
4 changes: 2 additions & 2 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ rerender`. An example of this can be found in [PR
- `build` string to search within `build` for example strings include
`py27_0` etc which can be useful for filtering specific versions of
packages.
- `search` will search within the package names for a match
- `search` will search within the package names for a match. The search is fuzzy by default. To get the packages with the exact given name, add the parameter `exact=1`.
### Conda Channels
Expand All @@ -193,7 +193,7 @@ rerender`. An example of this can be found in [PR
- `build` string to search within `build` for example strings include
`py27_0` etc which can be useful for filtering specific versions of
packages.
- `search` will search within the package names for a match
- `search` will search within the package names for a match. The search is fuzzy by default. To get the packages with the exact given name, add the parameter `exact=1`.
### REST API query format
Expand Down

0 comments on commit 6232074

Please sign in to comment.