cozodb / cozo

A transactional, relational-graph-vector database that uses Datalog for query. The hippocampus for AI!
https://cozodb.org
Mozilla Public License 2.0
3.44k stars 108 forks source link

Seems * can not be used in FTS ? #257

Open oddpxl opened 8 months ago

oddpxl commented 8 months ago

..or am I doing something wrong ?

Search result: Err( × --> 1:1 │ | │ 1 | *arlie │ | ^--- │ | │ = expected fts_expr

`

let result = db.run_script(
    "::fts create people:index_name {
        extractor: name,
        extract_filter: !is_null(name),
        tokenizer: Simple,
        filters:[Lowercase, Stemmer('english'), Stopwords('en')]
    }", 
    BTreeMap::new(),
    ScriptMutability::Mutable
);

println!("Index result: {:?}", result);

let mut parameters = BTreeMap::new();
parameters.insert("q".to_string().into(), DataValue::Str("*arlie".to_string().into()));
let result = db.run_script(
    "?[score, name, age] := ~people:index_name {name, age | query: $q, k: 10, filter: 1 + 1 == 2, score_kind: 'tf', bind_score: score }
    :order -score
    ", 
    parameters,
    ScriptMutability::Immutable
);

println!("Search result: {:?}", result);`
creatorrr commented 7 months ago

Yeah I can confirm that fts query with a prefixed star doesn't work.

REPL example:

=> :create people { name: String }
 status
--------
 "OK"

=> ::fts create people:index_name {
        extractor: name,
        extract_filter: !is_null(name),
        tokenizer: Simple,
        filters:[Lowercase, Stemmer('english'), Stopwords('en')]
    }
 status
--------
 "OK"

=> ?[name] <- [['Diwank']] :insert people {name}
 status
--------
 "OK"

=> ?[name] := ~people:index_name {name | query: 'wank', k: 10}
 name
------

=> ?[name] := ~people:index_name {name | query: 'Diwank', k: 10}
 name
----------
 "Diwank"

=> ?[name] := ~people:index_name {name | query: '*wank', k: 10}
  ×  --> 1:1
  │   |
  │ 1 | *wank
  │   | ^---
  │   |
  │   = expected fts_expr

=> ?[name] := ~people:index_name {name | query: 'Di*', k: 10}
 name
------