pub fn search(&self, query: &str, offset: i64, limit: i64) -> Result<EntriesResult<Record>> {
        use crate::schema::records::{self, dsl};

        // deprecated, telah digantikan dengan pre-set column latest lebih murah dan optimal
        // select * from (select *, rank() OVER (PARTITION BY loc order by last_updated desc) from records) as d where d.rank=1;

        let like_clause = format!("%{}%", query.to_lowercase());
        let mut filterer: Box<dyn BoxableExpression<records::table, _, SqlType = sql_types::Bool>> =
            Box::new(dsl::id.ne(0).and(dsl::latest.eq(true)));

        filterer = Box::new(filterer.and(lower(dsl::loc).like(&like_clause)));

        Ok(EntriesResult::new(
            dsl::records
                .filter(&filterer)
                .offset(offset)
                .limit(limit)
                .order(dsl::last_updated.desc())
                .load::<Record>(self.db)?,
            dsl::records
                .filter(filterer)
                .select(diesel::dsl::count(dsl::id))
                .first(self.db)?,
        ))
    }
/// Search for specific records only take the latest one for each location
Search for specific records only take the latest one for each location
Search for specific records only take the latest one for each location
pub fn search(&self, query: &str, offset: i64, limit: i64) -> Result<EntriesResult<Record>> {
        use crate::schema::records::{self, dsl};
        // deprecated, telah digantikan dengan pre-set column latest lebih murah dan optimal
        // select * from (select *, rank() OVER (PARTITION BY loc order by last_updated desc) from records) as d where d.rank=1;
        let like_clause = format!("%{}%", query.to_lowercase());
        let mut filterer: Box<dyn BoxableExpression<records::table, _, SqlType = sql_types::Bool>> =
            Box::new(dsl::id.ne(0).and(dsl::latest.eq(true)));
        filterer = Box::new(filterer.and(lower(dsl::loc).like(&like_clause)));
        Ok(EntriesResult::new(
            dsl::records
                .filter(&filterer)
                .offset(offset)
                .limit(limit)
                .order(dsl::last_updated.desc())
                .load::<Record>(self.db)?,
            dsl::records
                .filter(filterer)
                .select(diesel::dsl::count(dsl::id))
                .first(self.db)?,
        ))
    }
pub fn search ( & self , query : & str , offset : i64 , limit : i64 ) -> Result < EntriesResult < Record > > { use crate :: schema :: records :: { self , dsl } ; // deprecated, telah digantikan dengan pre-set column latest lebih murah dan optimal // select * from (select *, rank() OVER (PARTITION BY loc order by last_updated desc) from records) as d where d.rank=1; let like_clause = format ! ( " " query to_lowercase ( ) ) ; let mut filterer : Box < dyn BoxableExpression < records :: table , _ , SqlType = sql_types :: Bool > > = Box :: new ( dsl :: id . ne ( 0 ) . and ( dsl :: latest . eq ( true ) ) ) ; filterer = Box :: new ( filterer . and ( lower ( dsl :: loc ) . like ( & like_clause ) ) ) ; Ok ( EntriesResult :: new ( dsl :: records . filter ( & filterer ) . offset ( offset ) . limit ( limit ) . order ( dsl :: last_updated . desc ( ) ) . load :: < Record > ( self . db ) ? , dsl :: records . filter ( filterer ) . select ( diesel :: dsl :: count ( dsl :: id ) ) . first ( self . db ) ? , ) ) }
Search for specific records only take the latest one for each location
Search for specific records only take the latest one for each location
&self
query
&str
offset
i64
limit
i64
&self
query
&str
offset
i64
limit
i64