Skip to content

Commit

Permalink
fix: correct algo for score
Browse files Browse the repository at this point in the history
  • Loading branch information
philtweir committed Feb 22, 2024
1 parent 33cb55a commit 1773de2
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ authors = [
{name = "Metin Akat", email = "[email protected]"},
{name = "Phil Weir", email = "[email protected]"}
]
version = "0.3.11"
version = "0.3.12"
description = "Identify locations and tag them with UN-LOCODEs and ISO-3166-2 subdivisions."
readme = "README.md"
license = {file = "LICENSE.md"}
Expand Down
2 changes: 1 addition & 1 deletion python/berlin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
Location as Location
)

__version__ = "0.3.11"
__version__ = "0.3.12"
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use berlin_core::locations_db::{
use berlin_core::search::{Score, SearchTerm};

// We will cap scores to this number
pub const MAXIMUM_SCORE: i32 = 1000;
pub const MAXIMUM_SCORE: i32 = 10000;

#[pyclass]
struct LocationsDbProxy {
Expand Down Expand Up @@ -144,7 +144,7 @@ impl LocationProxy {
fn get_score(&self) -> Result<i32, PyErr> {
match self._score {
Some(score) => Ok(match i32::try_from(score.score) {
Ok(_score) => i32::max(MAXIMUM_SCORE, _score),
Ok(_score) => i32::min(MAXIMUM_SCORE, _score),
_ => MAXIMUM_SCORE,
}),
None => Err(PyAttributeError::new_err(format![
Expand Down
1 change: 1 addition & 0 deletions tests/test_berlin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def test_search_with_state(db):
assert list(loc.words) == ["abercarn"]

assert isinstance(loc.get_score(), int)
assert loc.get_score() == 1008
offset = query.find("Abercarn") or 0
assert loc.get_offset() == (offset, offset + len("Abercarn"))

Expand Down

0 comments on commit 1773de2

Please sign in to comment.