Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Better Search #47

Open
0xcaff opened this issue Jun 1, 2018 · 2 comments
Open

Better Search #47

0xcaff opened this issue Jun 1, 2018 · 2 comments

Comments

@0xcaff
Copy link
Member

0xcaff commented Jun 1, 2018

Currently search uses a simple LIKE"%query%" for queries. We should switch to full text search so that search works better. It will also be needed for implementing forte-music/schema#51 when it lands.

There doesn't seem to be SQlite full text search support in diesel. Here are some issues I've encountered while looking into this.

@0xcaff
Copy link
Member Author

0xcaff commented Jun 1, 2018

Here's a minimal example of using full text search:

main.rs

#[macro_use]
extern crate diesel;

mod database;

use database::email;
use diesel::prelude::*;

fn main() {
    let conn = SqliteConnection::establish("./test.sqlite").unwrap();

    let values = email::table
        .select((email::rowid, email::rank))
        .filter(email::whole_col.eq("john"))
        .first::<(i32, f32)>(&conn)
        .unwrap();

    println!("{:?}", values);
}

database.rs

table! {
    email(rowid) {
        rowid -> Integer,

        #[sql_name = "email"]
        whole_col -> Text,
        rank -> Float,
    }
}

up.sql

CREATE VIRTUAL TABLE email USING fts5(sender, title, body);

INSERT INTO email (sender, title, body) VALUES ('John Doe', 'Hello World', 'Welcome john to the land of the awesome');

Running

/usr/bin/cargo run --color=always --package diesel-fts --bin diesel-fts
   Compiling diesel-fts v0.1.0 (file:///home/me/projects/diesel-fts)
    Finished dev [unoptimized + debuginfo] target(s) in 1.39 secs
     Running `target/debug/diesel-fts`
(1, -0.000001375)

Process finished with exit code 0

@0xcaff
Copy link
Member Author

0xcaff commented Nov 30, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant