Skip to content

Commit

Permalink
feat(search): added skeleton for suggest func
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksasiriski committed Jun 21, 2024
1 parent b035242 commit eef938c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/search/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ func initializeSearchers(ctx context.Context, engs []engines.Name, timings confi
return searchers[:]
}

func initializeSuggesters(ctx context.Context, engs []engines.Name, timings config.CategoryTimings) []scraper.Suggester {
func initializeSuggesters(ctx context.Context, timings config.CategoryTimings) []scraper.Suggester {

Check failure on line 19 in src/search/init.go

View workflow job for this annotation

GitHub Actions / lint

func `initializeSuggesters` is unused (unused)
suggesters := suggesterArray()
for _, engName := range engs {
suggesters[engName].Init(ctx, timings)
for _, suggester := range suggesters {
suggester.Init(ctx, timings)
}
return suggesters[:]
}
11 changes: 9 additions & 2 deletions src/search/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ import (
"github.com/hearchco/agent/src/search/engines/options"
)

func validateParams(query string, opts options.Options) error {
func validateSuggestParams(query string, locale options.Locale) error {
if query == "" {
return fmt.Errorf("query can't be empty")
}
if opts.Locale == "" {
if locale == "" {
return fmt.Errorf("locale can't be empty")
}

return nil
}

func validateSearchParams(query string, opts options.Options) error {
validateSuggestParams(query, opts.Locale)

Check failure on line 21 in src/search/params.go

View workflow job for this annotation

GitHub Actions / lint

Error return value is not checked (errcheck)

if opts.Pages.Start < 0 {
return fmt.Errorf("pages start can't be negative")
}
Expand Down
2 changes: 1 addition & 1 deletion src/search/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func Search(query string, category category.Name, opts options.Options, catConf
// Capture start time.
startTime := time.Now()

if err := validateParams(query, opts); err != nil {
if err := validateSearchParams(query, opts); err != nil {
return nil, err
}

Expand Down
40 changes: 40 additions & 0 deletions src/search/suggest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package search

import (
"fmt"
"time"

"github.com/rs/zerolog/log"

"github.com/hearchco/agent/src/search/engines"
"github.com/hearchco/agent/src/search/engines/options"
"github.com/hearchco/agent/src/utils/anonymize"
)

func Suggest(query string, locale options.Locale) ([]string, error) {
// Capture start time.
startTime := time.Now()

if err := validateSuggestParams(query, locale); err != nil {
return nil, err
}

log.Debug().
Str("query", anonymize.String(query)).
Str("locale", locale.String()).
Msg("Suggesting")

// TODO: Implement the suggest function.
suggestions := []string{}
responders := []engines.Name{}

log.Debug().
Int("suggestions", len(suggestions)).
Str("query", anonymize.String(query)).
Str("responders", fmt.Sprintf("%v", responders)).
Dur("duration", time.Since(startTime)).
Msg("Scraping finished")

// Return the suggestions.
return suggestions, nil
}

0 comments on commit eef938c

Please sign in to comment.