< 返回版块

tokyohuang123 发表于 2021-10-08 14:14

    let result = product.filter(pdid.like(&i))
        .or_filter(pdname.like(&i))
        .or_filter(des.like(format!("{:?}",&i)+"*"))
        .or_filter(overview.like(format!("{:?}",&i)+"*"))
        .or_filter(feature.like(format!("{:?}",&i)+"*"))
非常奇怪这个like 每次都匹配不到东西
比如我匹配包含test开头的 它只匹配一个完整的test

评论区

写评论
作者 tokyohuang123 2021-10-12 10:07

我x 我没注意这个 谢谢🙏 这下真丢脸了

--
👇
Freddie Mercury: ``` let a_str = String::from("text"); println!("{:?}",&a_str); // "text" println!("{}",&a_str); // text


--  
👇  
tokyohuang123: ```

    let result = product.filter(pdid.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .or_filter(pdname.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .or_filter(des.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .or_filter(overview.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .or_filter(feature.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .or_filter(application.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .or_filter(type_.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .or_filter(states.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .or_filter(admin.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .or_filter(date_created.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .or_filter(date_updated.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .load::<Product>(&db_connection)?;
    Ok(result)
改成这样都一个匹配不了 
Freddie Mercury 2021-10-11 14:22
let a_str = String::from("text");
println!("{:?}",&a_str); // "text"
println!("{}",&a_str); // text

--
👇
tokyohuang123: ```

let result = product.filter(pdid.like(format!("{:?}","%".to_owned()+&i)+"%"))
    .or_filter(pdname.like(format!("{:?}","%".to_owned()+&i)+"%"))
    .or_filter(des.like(format!("{:?}","%".to_owned()+&i)+"%"))
    .or_filter(overview.like(format!("{:?}","%".to_owned()+&i)+"%"))
    .or_filter(feature.like(format!("{:?}","%".to_owned()+&i)+"%"))
    .or_filter(application.like(format!("{:?}","%".to_owned()+&i)+"%"))
    .or_filter(type_.like(format!("{:?}","%".to_owned()+&i)+"%"))
    .or_filter(states.like(format!("{:?}","%".to_owned()+&i)+"%"))
    .or_filter(admin.like(format!("{:?}","%".to_owned()+&i)+"%"))
    .or_filter(date_created.like(format!("{:?}","%".to_owned()+&i)+"%"))
    .or_filter(date_updated.like(format!("{:?}","%".to_owned()+&i)+"%"))
    .load::<Product>(&db_connection)?;
Ok(result)

改成这样都一个匹配不了


作者 tokyohuang123 2021-10-11 13:53

    let result = product.filter(pdid.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .or_filter(pdname.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .or_filter(des.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .or_filter(overview.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .or_filter(feature.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .or_filter(application.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .or_filter(type_.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .or_filter(states.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .or_filter(admin.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .or_filter(date_created.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .or_filter(date_updated.like(format!("{:?}","%".to_owned()+&i)+"%"))
        .load::<Product>(&db_connection)?;
    Ok(result)
改成这样都一个匹配不了 
作者 tokyohuang123 2021-10-11 10:25
    let id_string = &path.0;
    let i: String = urlencoding::decode(format!("{}",id_string.as_str()).as_str()).expect("UTF-8").to_string();

    let result = product.filter(pdid.like(format!("{:?}",&i)+"%"))
        .or_filter(pdname.like(format!("{:?}",&i)+"%"))
        .or_filter(des.like(format!("{:?}",&i)+"%"))
        .or_filter(overview.like(format!("{:?}",&i)+"%"))
        .or_filter(feature.like(format!("{:?}",&i)+"*"))
        .or_filter(application.like(format!("{:?}",&i)+"%"))
        .or_filter(type_.like(format!("{:?}",&i)+"%"))
        .or_filter(states.like(format!("{:?}",&i)+"%"))
        .or_filter(admin.like(format!("{:?}",&i)+"%"))
        .or_filter(date_created.like(format!("{:?}",&i)+"%"))
        .or_filter(date_updated.like(format!("{:?}",&i)+"%"))
        .load::<Product>(&db_connection)?;
    Ok(result)
}
目前这样还是不行 而且现在连完整匹配都匹配不到了

--
👇
Freddie Mercury: 前面两句like没用通配符啊,所以只能匹配完整的test,另外通配符就是%啊

    let result = product.filter(pdid.like(&i))
        .or_filter(pdname.like(&i))

--
👇
tokyohuang123: ··· 用%不行才用*的 ···

👇
langzi.me: like要用%。 你确定你会sql吗。

作者 tokyohuang123 2021-10-11 10:10
好我试试 谢谢

--
👇
Freddie Mercury: 前面两句like没用通配符啊,所以只能匹配完整的test,另外通配符就是%啊

    let result = product.filter(pdid.like(&i))
        .or_filter(pdname.like(&i))

--
👇
tokyohuang123: ··· 用%不行才用*的 ···

👇
langzi.me: like要用%。 你确定你会sql吗。

Freddie Mercury 2021-10-09 14:50

前面两句like没用通配符啊,所以只能匹配完整的test,另外通配符就是%啊

    let result = product.filter(pdid.like(&i))
        .or_filter(pdname.like(&i))

--
👇
tokyohuang123: ··· 用%不行才用*的 ···

👇
langzi.me: like要用%。 你确定你会sql吗。

作者 tokyohuang123 2021-10-09 09:07

··· 用%不行才用*的 ···

👇
langzi.me: like要用%。 你确定你会sql吗。

langzi.me 2021-10-08 15:33

like要用%。 你确定你会sql吗。

1 共 8 条评论, 1 页