-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from xxxsen/xxxsen/feature/optimize_category_se…
…arch Xxxsen/feature/optimize category search
- Loading branch information
Showing
19 changed files
with
189 additions
and
136 deletions.
There are no files selected for viewing
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
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
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
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,40 @@ | ||
package searcher | ||
|
||
import ( | ||
"context" | ||
"yamdc/model" | ||
"yamdc/number" | ||
|
||
"github.com/xxxsen/common/logutil" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type categorySearcher struct { | ||
defSearcher []ISearcher | ||
catSearchers map[number.Category][]ISearcher | ||
} | ||
|
||
func NewCategorySearcher(def []ISearcher, cats map[number.Category][]ISearcher) ISearcher { | ||
return &categorySearcher{defSearcher: def, catSearchers: cats} | ||
} | ||
|
||
func (s *categorySearcher) Name() string { | ||
return "category" | ||
} | ||
|
||
func (s *categorySearcher) Search(ctx context.Context, n *number.Number) (*model.AvMeta, bool, error) { | ||
cat := n.GetCategory() | ||
//没分类, 那么使用主链进行查询 | ||
//存在分类, 但是分类对应的链没有配置, 则使用主链进行查询 | ||
//如果已经存在分类链, 则不再进行降级 | ||
logger := logutil.GetLogger(ctx).With(zap.String("cat", string(cat))) | ||
chain := s.defSearcher | ||
if cat != number.CatDefault { | ||
if c, ok := s.catSearchers[cat]; ok { | ||
chain = c | ||
logger.Debug("use cat chain for search") | ||
} | ||
} | ||
|
||
return performGroupSearch(ctx, n, chain) | ||
} |
File renamed without changes.
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
Oops, something went wrong.