sourcegraph / sourcegraph-public-snapshot

Code AI platform with Code Search & Cody
https://sourcegraph.com
Other
10.11k stars 1.29k forks source link

before: search keyword in diff search is ineffective #46026

Open sqs opened 1 year ago

sqs commented 1 year ago

In the query file:featureflag type:diff before:7months (which I was doing to see who to thank for building our feature flag system!), the before: operator is not taking effect.

The results include matches from 10 and 12 days ago. I expect no results newer than 7 months.

image

/cc @sourcegraph/search-product

sqs commented 1 year ago

Hmm, it might be that after: and before: got switched, since after: shows no results (which is unexpected, since there are certainly results in the last 7 months!).

https://sourcegraph.sourcegraph.com/search?q=context%3Asourcegraph+f%3Afeatureflag+type%3Adiff+repo%3Asourcegraph%24+after%3A6months&patternType=standard&sm=0&groupBy=author

camdencheek commented 1 year ago

The natural date parser we use expects relative dates of the form "7 months ago". Based on a couple of tests, it appears to be tokenizing the 7, failing to find the keyword ago, and interpreting 7months as 7:00 today, which would explain why there doesn't seem to be any filtering going on with before

We used that package so we could move quickly, but we might eventually want to just write our own.

limitedmage commented 1 year ago

Can we instead use search query code intel so that the user hovers over the time string and sees the timestamp? Similar to what we do for eg. regex image

limitedmage commented 1 year ago

This would also fix the ambiguity of timezone parsing (we always parse exact times as UTC if they don't have a timezone.

camdencheek commented 1 year ago

Ooh, that's a cool idea. I could definitely expose the date parsing via the API, then it would just be a matter of hooking up the hovers to call that

jtibshirani commented 6 months ago

@camdencheek can we close this out now that you improved the semantics of 'before' in https://github.com/sourcegraph/sourcegraph/pull/61513?

camdencheek commented 6 months ago

I think this is still relevant. I just tried the search Quinn mentioned, and it still interprets 7months incorrectly. I expect to fix this, we'd probably need to fork naturaldate and update the parser.

Also, I do still think it would be helpful to have a hover that shows exactly how your relative time was interpreted. Especially since we interpret everything in UTC rather than local time. Right now, there is no real indication that your query isn't doing what you want it to except that you're getting commits that are more recent than you asked for.