Skip to content

search: compose lucky rules for lang, type, unordered

Warren Gifford requested to merge rvt/lucky-result-kind-compose into main

Created by: rvantonder

Stacked on https://github.com/sourcegraph/sourcegraph/pull/37059

This statically composes some of the previous rules, so that you can get pretty nice and complex interpretations for a query like:

go commit monitor code runs as any of (in priority):

  • usual literal search
  • type:commit lang:Go monitor code (trigger type and lang rules)
  • type:commit go monitor code (trigger type rule)
  • lang:Go commit monitor code (trigger lang rule)
  • type:commit lang:Go (monitor AND code) (trigger lang rule and commit rule, then unorder)
  • etc.

In the ideal solution, we don't want to enumerate the composition of these rules statically like I'm doing here, but generate them based on their properties. But I don't yet know what properties play well and what combinators will be useful for generating, so see this as me exploring that direction and making observations.

Observations so far:

  • There is an either/or/both strategy where ordering of rule application doesn't matter, and the rules are disjoint. For example, applying lang and type rules are disjoint, and their application order doesn't matter. We prefer to run a search where both applies, before attempting the either/or property.
  • I haven't thought deeply about it, but I believe the either/or/both strategy ensures unique results (important characteristic, if we want to minimize the deduplication).
  • There is a general multi-pattern strategy that composes on top of disjoint rules that turn patterns into parameters--one example is interpreting unordered patterns / rule.
  • It seems pretty clear that the multi-pattern strategy is prone to duplication.

Test plan

Updated tests.

Merge request reports

Loading