blugelabs / bluge

indexing library for Go
Apache License 2.0
1.9k stars 125 forks source link

Added accessors to query structs #49

Closed voldyman closed 3 years ago

voldyman commented 3 years ago

Background

When i use the query_string package, i get a query tree but it's opaque and can't be modified. I want to use custom analyzers, boosts, parameters for fields queries.

I've implemented a QueryVisitor in my code, which let's me traverse the query tree and modify it as needed but the problem is that once a Query is generated, it's parameters are not visible.

Solution

With this change, I can read the properties of the sub-queries and transform them according to my logic.

Note: This commit only updates one existing method SetMinShould to return *BooleanQuery to be consistent with other methods and convenience.

Note2: My visit interface looks like the following

type QueryVisitor interface {
    VisitBooleanQuery(q *bluge.BooleanQuery) bluge.Query
    VisitDateRangeQuery(q *bluge.DateRangeQuery) bluge.Query
    VisitFuzzyQuery(q *bluge.FuzzyQuery) bluge.Query
    VisitMatchAllQuery(q *bluge.MatchAllQuery) bluge.Query
    VisitMatchNoneQuery(q *bluge.MatchNoneQuery) bluge.Query
    VisitMatchPhraseQuery(q *bluge.MatchPhraseQuery) bluge.Query
    VisitMatchQuery(q *bluge.MatchQuery) bluge.Query
    VisitTermQuery(q *bluge.TermQuery) bluge.Query
    VisitTermRangeQuery(q *bluge.TermRangeQuery) bluge.Query
    VisitRegexpQuery(q *bluge.RegexpQuery) bluge.Query
    VisitWildcardQuery(q *bluge.WildcardQuery) bluge.Query
    VisitMultiPhraseQuery(q *bluge.MultiPhraseQuery) bluge.Query
}
mschoch commented 3 years ago

@voldyman this looks good to me. One question, is there a reason not all queries are updated here? I see only the GeoBoundingPolygonQuery and not BoudingBox or PointDistance. I didn't exhaustively look for all of them, just noticed those two missing...

voldyman commented 3 years ago

There is not reason to skip them, I just missed them i think.

Let me push another commit with accessors for them.