Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add an all_keywords parameter to the search route
Pass along any specified value for the all_keywords parameter to the
API request to search crates.

This lets us manually construct URLs in the browser like:

- /search?all_keywords=foo+bar
- /search?all_keywords=foo+bar&q=test

but there is no form field in the search form as yet; eventually, we'll
need an "advanced search" form or similar.
  • Loading branch information
carols10cents committed Nov 2, 2019
1 parent 547339a commit 9a3485b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/controllers/application.js
Expand Up @@ -28,6 +28,7 @@ export default Controller.extend(EKMixin, {
queryParams: {
q: this.searchQuery,
page: 1,
all_keywords: null,
},
});
},
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/search.js
Expand Up @@ -9,7 +9,7 @@ import PaginationMixin from '../mixins/pagination';

export default Controller.extend(PaginationMixin, {
search: service(),
queryParams: ['q', 'page', 'per_page', 'sort'],
queryParams: ['all_keywords', 'page', 'per_page', 'q', 'sort'],
q: alias('search.q'),
page: '1',
per_page: 10,
Expand Down
3 changes: 2 additions & 1 deletion app/routes/search.js
Expand Up @@ -2,8 +2,9 @@ import Route from '@ember/routing/route';

export default Route.extend({
queryParams: {
q: { refreshModel: true },
all_keywords: { refreshModel: true },
page: { refreshModel: true },
q: { refreshModel: true },
sort: { refreshModel: true },
},

Expand Down
5 changes: 4 additions & 1 deletion src/controllers/krate/search.rs
Expand Up @@ -99,7 +99,10 @@ pub fn search(req: &mut dyn Request) -> CargoResult<Response> {
use diesel::sql_types::Array;
sql_function!(#[aggregate] fn array_agg<T>(x: T) -> Array<T>);

let names: Vec<_> = kws.split_whitespace().map(|name| name.to_lowercase()).collect();
let names: Vec<_> = kws
.split_whitespace()
.map(|name| name.to_lowercase())
.collect();

query = query.filter(
// FIXME: Just use `.contains` in Diesel 2.0
Expand Down

0 comments on commit 9a3485b

Please sign in to comment.