Compose query conditions in Tantivy

Compose query conditions in Tantivy

Tantivy (https://github.com/quickwit-oss/tantivy)

official documentation: https://github.com/quickwit-oss/tantivy/blob/main/ARCHITECTURE.md#query-define-and-compose-queries

Different queries can be combined using the BooleanQuery. Tantivy comes with different types of queries and can be extended by implementing the Query, Weight, and Scorer traits.

Compose query conditions(query_parser.rs):

    let custom_query = BooleanQuery::new(vec![
        (
            Occur::Must,
            Box::new(RangeQuery::new_f64(lat, 1234.1231f64..1234.1232f64)),
        ),
        (
            Occur::Must,
            Box::new(RangeQuery::new_f64(long, 4321.4312f64..4321.4313f64)),
        ),
        (
            Occur::Must,
            Box::new(TermQuery::new(
                Term::from_field_text(body, "denis"),
                IndexRecordOption::WithFreqs,
            )),
        ),
    ]); 

will get similar results to:

    let query = query_parser
        .parse_query("+lat:[1234.1231 TO 1234.1232} 
            +long:[4321.4312 TO 4321.4313} +body:denis")?;

Related Posts