-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding search controller, directory processor and command
- Loading branch information
Showing
8 changed files
with
179 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package record | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"strings" | ||
|
||
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/cfg" | ||
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base" | ||
"github.com/rusq/slackdump/v3/internal/chunk" | ||
"github.com/rusq/slackdump/v3/internal/chunk/control" | ||
) | ||
|
||
var CmdSearch = &base.Command{ | ||
UsageLine: "slackdump search [flags] query terms", | ||
Short: "records search results matching the given query", | ||
Long: `Searches for messages matching criteria.`, | ||
RequireAuth: true, | ||
Run: runSearch, | ||
PrintFlags: true, | ||
} | ||
|
||
func runSearch(ctx context.Context, cmd *base.Command, args []string) error { | ||
if len(args) == 0 { | ||
base.SetExitStatus(base.SInvalidParameters) | ||
return errors.New("missing query parameter") | ||
} | ||
query := strings.Join(args, " ") | ||
|
||
sess, err := cfg.SlackdumpSession(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cd, err := chunk.CreateDir(cfg.Output) | ||
if err != nil { | ||
base.SetExitStatus(base.SGenericError) | ||
return err | ||
} | ||
defer cd.Close() | ||
|
||
stream := sess.Stream() | ||
ctrl := control.NewSearch(cd, stream) | ||
|
||
return ctrl.Search(ctx, query) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package control | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/rusq/slackdump/v3" | ||
"github.com/rusq/slackdump/v3/internal/chunk" | ||
"github.com/rusq/slackdump/v3/logger" | ||
"golang.org/x/sync/errgroup" | ||
) | ||
|
||
type Search struct { | ||
cd *chunk.Directory | ||
s *slackdump.Stream | ||
lg logger.Interface | ||
} | ||
|
||
func NewSearch(cd *chunk.Directory, s *slackdump.Stream) *Search { | ||
return &Search{cd: cd, s: s, lg: logger.Default} | ||
} | ||
|
||
func (s *Search) Search(ctx context.Context, query string) error { | ||
var eg errgroup.Group | ||
start := time.Now() | ||
eg.Go(func() error { | ||
return searchWorker(ctx, s.s, s.cd, query) | ||
}) | ||
eg.Go(func() error { | ||
return workspaceWorker(ctx, s.s, s.cd) | ||
}) | ||
if err := eg.Wait(); err != nil { | ||
return err | ||
} | ||
s.lg.Printf("search for query %q completed in: %s", query, time.Since(start)) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package dirproc | ||
|
||
import "github.com/rusq/slackdump/v3/internal/chunk" | ||
|
||
type Search struct { | ||
*baseproc | ||
} | ||
|
||
func NewSearch(dir *chunk.Directory) (*Search, error) { | ||
p, err := newBaseProc(dir, "search") | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &Search{baseproc: p}, nil | ||
} |