Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

case: does not have any effect within nested expressions #548

Open
isker opened this issue Feb 25, 2023 · 0 comments
Open

case: does not have any effect within nested expressions #548

isker opened this issue Feb 25, 2023 · 0 comments

Comments

@isker
Copy link
Contributor

isker commented Feb 25, 2023

Here are some input query strings and the results of parsing them. case: seems to not have any effect on the parsed query unless it's in the top-level expression.

foo bar -> (and substr:"foo" substr:"bar")
foo bar case:yes -> (and case_substr:"foo" case_substr:"bar")
foo bar case:no -> (and substr:"foo" substr:"bar")

foo or bar -> (or substr:"foo" substr:"bar")
foo or bar case:yes -> (or case_substr:"foo" case_substr:"bar") 
foo or bar case:no -> (or substr:"foo" substr:"bar") 

# `case:` does nothing if not at the top level.
(foo case:yes) bar -> (and substr:"foo" substr:"bar")
(case:yes foo) bar -> (and substr:"foo" substr:"bar")
(case:yes foo (bar)) -> (and substr:"foo" substr:"bar")

case: has special "application" logic (as it only modifies other expressions instead of doing anything on its own) and I suspect there is something wrong with it in that regard:

zoekt/query/parse.go

Lines 322 to 339 in 2560773

for _, q := range qs {
switch s := q.(type) {
case *caseQ:
setCase = s.Flavor
case *Type:
if s.Type < typeT {
typeT = s.Type
}
default:
newQS = append(newQS, q)
}
}
qs = mapQueryList(newQS, func(q Q) Q {
if sc, ok := q.(setCaser); ok {
sc.setCase(setCase)
}
return q
})

I believe the problem is that the logic to identify caseQ expressions in that for-loop only iterates over top-level expressions. It needs to iterate the entire tree of expressions, with lower caseQs overriding higher ones.

(By that reasoning it may be that Type expressions have the same problem, but I don't really understand what those are supposed to do even normally 🌞.)

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

No branches or pull requests

1 participant