Skip to content

search: fix scaling factor of indexed search result count

Administrator requested to merge rvt/um-scaling-factor-wut into master

Created by: rvantonder

We use a scaling factor in indexed search set how many matches/results we want to see based on how many repos are matched. The intuition is:

  • low number of repos to search -> give us more results -> set a higher scaling factor k
  • high number of repos to search -> give us fewer results -> set a lower scaling factor k

Snippet of the code:

        k := 1                                                                                                                                                          
        switch {                                                                                                                                                        
        case numRepos <= 500:                                                                                                                                           
                k = 2                                                                                                                                                   
        case numRepos <= 100:   // unreachable                                                                                                                                        
                k = 3                                                                                                                                                   
        case numRepos <= 50:    // unreachable                                                                                                                                        
                k = 5                                                                                                                                                   
        case numRepos <= 25:    // ... etc.                                                                                                                                         
                k = 8                                                                                                                                                   
        case numRepos <= 10:                                                                                                                                            
                k = 10                                                                                                                                                  
        case numRepos <= 5:                                                                                                                                             
                k = 100                                                                                                                                                 
        }  

Since this is Go code, not C, there is no fallthrough. k is basically always 2, unless numRepos > 500 in which case it is 1. So we basically always ask for very few results for small number of repos.

I have some concern that the intended scaling factor hasn't been validated very well (I mean validated empirically, as in, users have been exposed to this behavior) since it has basically never worked. It's worth fixing to the intended meaning and seeing how things go, because it does solve some existing issues.

I discovered this because I'm using indexed search for structural search and this issue affects it also. This fix does help with managing some results behavior there, and I checked that this also addresses #7596 and therefore pretty confident this is one significant underlying issue affecting weird behaviors in unindexed search.

Merge request reports

Loading