Skip to content

Commit

Permalink
fix: return resultMap instead of relay
Browse files Browse the repository at this point in the history
  • Loading branch information
k4lizen committed Feb 9, 2024
1 parent 43b244a commit 7056087
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/search/perform.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,27 @@ func PerformSearch(query string, options engines.Options, conf *config.Config) [
searchTimer := time.Now()

query, timings, enginesToRun := procBang(query, &options, conf)

query = url.QueryEscape(query)

log.Debug().
Str("queryAnon", anonymize.String(query)).
Str("queryHash", anonymize.HashToSHA256B64(query)).
Msg("Searching")

resTimer := time.Now()
log.Debug().Msg("Waiting for results from engines...")
relay := runEngines(enginesToRun, query, options, conf.Settings, timings)

resultMap := runEngines(enginesToRun, query, options, conf.Settings, timings)

log.Debug().
Int64("ms", time.Since(resTimer).Milliseconds()).
Msg("Got results")

rankTimer := time.Now()
log.Debug().Msg("Ranking...")
results := rank.Rank(relay.ResultMap, conf.Categories[options.Category].Ranking) // have to make copy, since its a map value

results := rank.Rank(resultMap, conf.Categories[options.Category].Ranking)

rankTimeSince := time.Since(rankTimer)
log.Debug().
Int64("ms", rankTimeSince.Milliseconds()).
Expand All @@ -53,14 +57,14 @@ func PerformSearch(query string, options engines.Options, conf *config.Config) [
return results
}

func runEngines(engs []engines.Name, query string, options engines.Options, settings map[engines.Name]config.Settings, timings config.Timings) *bucket.Relay {
func runEngines(engs []engines.Name, query string, options engines.Options, settings map[engines.Name]config.Settings, timings config.Timings) map[string]*result.Result {
config.EnabledEngines = engs
log.Info().
Int("number", len(config.EnabledEngines)).
Str("engines", fmt.Sprintf("%v", config.EnabledEngines)).
Msg("Enabled engines")

relay := &bucket.Relay{
relay := bucket.Relay{
ResultMap: make(map[string]*result.Result),
}

Expand All @@ -74,7 +78,7 @@ func runEngines(engs []engines.Name, query string, options engines.Options, sett
defer wg.Done()
// if an error can be handled inside, it wont be returned
// runs the Search function in the engine package
err := engineStarter[eng](context.Background(), query, relay, options, settings[eng], timings)
err := engineStarter[eng](context.Background(), query, &relay, options, settings[eng], timings)
if err != nil {
log.Error().
Err(err).
Expand All @@ -85,5 +89,5 @@ func runEngines(engs []engines.Name, query string, options engines.Options, sett
}

wg.Wait()
return relay
return relay.ResultMap
}

0 comments on commit 7056087

Please sign in to comment.