blevesearch / bleve

A modern text/numeric/geo-spatial/vector indexing library for go
Apache License 2.0
10.1k stars 686 forks source link

Query string query does not support AND/OR/NOT? #1716

Open lucasbbb opened 2 years ago

lucasbbb commented 2 years ago

It seems like the AND/OR/NOT operators are useless in the Query String Query, which is different from Lucene. Will these operators be supported in the future?

    indexMapping := bleve.NewIndexMapping()
    index, _ := bleve.NewMemOnly(indexMapping)
    index.Index("111111", map[string]interface{}{"name": "foo", "age": 1024})
    index.Index("222222", map[string]interface{}{"name": "bar", "age": 1024})
    index.Index("333333", map[string]interface{}{"name": "foo", "age": 64})

    q := bleve.NewQueryStringQuery("name:foo AND age:1024")
    req := bleve.NewSearchRequest(q)

    res, _ := index.Search(req)
    fmt.Println(res)
3 matches, showing 1 through 3, took 203.67µs
    1. 111111 (0.444550)
    2. 333333 (0.197578)
    3. 222222 (0.024697)
abhinavdangeti commented 2 years ago

@lucasbbb your syntax is incorrect.

Here's the query string equivalent for name:foo AND age:1024:

+name:foo +age:1024

Here's the query string equivalent for name:foo OR age:1024:

name:foo age:1024

Here's the query string equivalent for not name:foo:

-name:foo

No plans for supporting the AND/OR/NOT operators for the query string queries at the moment.

lucasbbb commented 2 years ago

@lucasbbb your syntax is incorrect.

Here's the query string equivalent for name:foo AND age:1024:

+name:foo +age:1024

Here's the query string equivalent for name:foo OR age:1024:

name:foo age:1024

Here's the query string equivalent for not name:foo:

-name:foo

Thanks for the reply. But how could I combine multiple query statements, for example:

name:foo AND (age:1024 OR age:64)
abhinavdangeti commented 2 years ago

The query string syntax support that we have at the moment is a bit limited. I'd recommend using the conjuncts and disjuncts constructs for your case:

{"conjuncts": [{"query": "name:foo"}, {"disjuncts": [{"query": "age:1024"}, {"query": "age:64"}]}]}
lucasbbb commented 2 years ago

Thanks. I see. I notice that the QueryStringQuery is still parsed through goyacc which has been deprecated long long ago. How about refactor it with ANTLR4? Do you have this plan? If not, is it welcomed to submit a PR?

abhinavdangeti commented 2 years ago

We don't have a plan there for the moment. However, we'd welcome a PR if you're willing to make a contribution. We'll review it and consider it if it aligns with our roadmap.