Skip to content

Commit

Permalink
add geo_score as sort option
Browse files Browse the repository at this point in the history
  • Loading branch information
pleary committed Sep 19, 2024
1 parent b8216e7 commit 5bc93a0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/models/observation.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const Observation = class Observation extends Model {
delete this.sound_licenses;
delete this.photos_count;
delete this.sounds_count;
delete this.geo_score;
}

makeBackwardsCompatible( ) {
Expand Down
3 changes: 3 additions & 0 deletions lib/models/observation_query_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,9 @@ ObservationQueryBuilder.reqToElasticQueryComponents = async req => {
case "updated_at":
sort = { updated_at: sortOrder };
break;
case "geo_score":
sort = { geo_score: sortOrder };
break;
case "none":
break;
default:
Expand Down
7 changes: 5 additions & 2 deletions lib/views/swagger_v1.yml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2758,11 +2758,14 @@ parameters:
description: Sort field
default: created_at
enum:
- created_at
- geo_score
- id
- observed_on
- random
- species_guess
- updated_at
- votes
- id
- created_at
only_id:
name: only_id
type: boolean
Expand Down
15 changes: 8 additions & 7 deletions openapi/schema/request/observations_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,17 @@ module.exports = Joi.object( ).keys( {
order: Joi.string( ).valid(
"desc",
"asc"
),
).default( "desc" ),
order_by: Joi.string( ).valid(
"created_at",
"geo_score",
"id",
"observed_on",
"updated_at",
"random",
"species_guess",
"votes",
"id",
"created_at",
"random"
),
"updated_at",
"votes"
).default( "created_at" ),
only_id: Joi.boolean( ),
fields: Joi.any( )
.description( "Attribute fields to return in the response" )
Expand Down
5 changes: 5 additions & 0 deletions test/controllers/v1/observations_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,11 @@ describe( "ObservationsController", ( ) => {
const q = await Q( { order_by: "id" } );
expect( q.sort ).to.eql( { id: "desc" } );
} );

it( "sorts by geo_score", async ( ) => {
const q = await Q( { order_by: "geo_score" } );
expect( q.sort ).to.eql( { geo_score: "desc" } );
} );
} );

describe( "index", ( ) => {
Expand Down

0 comments on commit 5bc93a0

Please sign in to comment.