caio.co/de/cantine

Alias RecipeId<=>u64

Id
11ea27e5d8346a526190709c2e91787617063650
Author
Caio
Commit time
2019-12-06T14:56:43+01:00

Modified crates/cantine/src/index.rs

@@ -11,7 +11,7

use crate::model::{
FeaturesAggregationQuery, FeaturesAggregationResult, FeaturesCollector, FeaturesFilterFields,
- Recipe, SearchCursor, SearchQuery, Sort,
+ Recipe, RecipeId, SearchCursor, SearchQuery, Sort,
};

use tique::{
@@ -102,7 +102,7

pub type CantineSearchResult = (
usize,
- Vec<u64>,
+ Vec<RecipeId>,
Option<SearchCursor>,
Option<FeaturesAggregationResult>,
);
@@ -127,7 +127,7
})
}

- fn interpret_query(&self, query: &SearchQuery) -> Result<Box<dyn Query>> {
+ pub fn interpret_query(&self, query: &SearchQuery) -> Result<Box<dyn Query>> {
let mut subqueries: Vec<(Occur, Box<dyn Query>)> = Vec::new();

if let Some(fulltext) = &query.fulltext {
@@ -153,7 +153,7
&self,
searcher: &Searcher,
addresses: &[SearchMarker<T>],
- ) -> Result<Vec<u64>> {
+ ) -> Result<Vec<RecipeId>> {
let mut items = Vec::with_capacity(addresses.len());

for addr in addresses.iter() {
@@ -175,7 +175,7
limit: usize,
sort: Sort,
after: SearchCursor,
- ) -> Result<(usize, Vec<u64>, Option<SearchCursor>)> {
+ ) -> Result<(usize, Vec<RecipeId>, Option<SearchCursor>)> {
macro_rules! condition_from_score {
($score:expr) => {{
let after_score = $score;

Modified crates/cantine/src/model.rs

@@ -8,7 +8,7
pub struct Recipe {
pub uuid: Uuid,

- pub recipe_id: u64,
+ pub recipe_id: RecipeId,
pub name: String,
pub crawl_url: String,

@@ -20,6 +20,8

pub features: Features,
}
+
+pub type RecipeId = u64;

impl DatabaseRecord for Recipe {
fn get_id(&self) -> u64 {
@@ -119,16 +121,16

// FIXME Saner serialization
#[derive(Serialize, Deserialize, Debug, Default)]
-pub struct SearchCursor(u64, u64);
+pub struct SearchCursor(u64, RecipeId);

impl SearchCursor {
pub const START: Self = Self(0, 0);

- pub fn new(score: u64, recipe_id: u64) -> Self {
+ pub fn new(score: u64, recipe_id: RecipeId) -> Self {
Self(score, recipe_id)
}

- pub fn from_f32(score: f32, recipe_id: u64) -> Self {
+ pub fn from_f32(score: f32, recipe_id: RecipeId) -> Self {
Self(score.to_bits() as u64, recipe_id)
}

@@ -136,7 +138,7
self.0 == 0 && self.1 == 0
}

- pub fn recipe_id(&self) -> u64 {
+ pub fn recipe_id(&self) -> RecipeId {
self.1
}