Modify Search functions to take a slice of keyword as argument
parent
bb7b4c59ad
commit
5230dbbd17
2
main.go
2
main.go
|
|
@ -62,7 +62,7 @@ func searchCommand(args []string) {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
res, _ := registry.Search(args[0])
|
res, _ := registry.Search(args)
|
||||||
for _, fileInfo := range res {
|
for _, fileInfo := range res {
|
||||||
printer.AddRow(Row{fileInfo.Name, formatSize(fileInfo.Size), fileInfo.Url})
|
printer.AddRow(Row{fileInfo.Name, formatSize(fileInfo.Size), fileInfo.Url})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
search.go
11
search.go
|
|
@ -22,7 +22,7 @@ type XdccFileInfo struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type XdccSearchProvider interface {
|
type XdccSearchProvider interface {
|
||||||
Search(fileName string) ([]XdccFileInfo, error)
|
Search(keywords []string) ([]XdccFileInfo, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type XdccProviderRegistry struct {
|
type XdccProviderRegistry struct {
|
||||||
|
|
@ -43,14 +43,14 @@ func (registry *XdccProviderRegistry) AddProvider(provider XdccSearchProvider) {
|
||||||
|
|
||||||
const MaxResults = 1024
|
const MaxResults = 1024
|
||||||
|
|
||||||
func (registry *XdccProviderRegistry) Search(fileName string) ([]XdccFileInfo, error) {
|
func (registry *XdccProviderRegistry) Search(keywords []string) ([]XdccFileInfo, error) {
|
||||||
allResults := make([]XdccFileInfo, 0, MaxResults)
|
allResults := make([]XdccFileInfo, 0, MaxResults)
|
||||||
|
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
wg.Add(len(registry.providerList))
|
wg.Add(len(registry.providerList))
|
||||||
for _, p := range registry.providerList {
|
for _, p := range registry.providerList {
|
||||||
go func(p XdccSearchProvider) {
|
go func(p XdccSearchProvider) {
|
||||||
res, err := p.Search(fileName)
|
res, err := p.Search(keywords)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
@ -121,8 +121,9 @@ func (p *XdccEuProvider) parseFields(fields []string) (*XdccFileInfo, error) {
|
||||||
return fInfo, nil
|
return fInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *XdccEuProvider) Search(fileName string) ([]XdccFileInfo, error) {
|
func (p *XdccEuProvider) Search(keywords []string) ([]XdccFileInfo, error) {
|
||||||
searchkey := strings.Join(strings.Fields(fileName), "+")
|
keywordString := strings.Join(keywords, " ")
|
||||||
|
searchkey := strings.Join(strings.Fields(keywordString), "+")
|
||||||
res, err := http.Get(XdccEuURL + "?searchkey=" + searchkey)
|
res, err := http.Get(XdccEuURL + "?searchkey=" + searchkey)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue