use lemmy_utils::LemmyError;
use once_cell::sync::Lazy;
use regex::Regex;
-use serde::{Deserialize, Serialize};
use std::{env, env::VarError, io::Write};
use url::Url;
env::var("LEMMY_DATABASE_URL")
}
-#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
-pub enum SortType {
- Active,
- Hot,
- New,
- TopDay,
- TopWeek,
- TopMonth,
- TopYear,
- TopAll,
- MostComments,
- NewComments,
-}
-
-#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
-pub enum ListingType {
- All,
- Local,
- Subscribed,
- Community,
-}
-
-#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
-pub enum SearchType {
- All,
- Comments,
- Posts,
- Communities,
- Users,
- Url,
-}
-
-pub fn from_opt_str_to_opt_enum<T: std::str::FromStr>(opt: &Option<String>) -> Option<T> {
- opt.as_ref().and_then(|t| T::from_str(t).ok())
-}
-
pub fn fuzzy_search(q: &str) -> String {
let replaced = q.replace('%', "\\%").replace('_', "\\_").replace(' ', "%");
format!("%{}%", replaced)