grepai-search-boosting

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GrepAI Search Boosting

GrepAI 搜索结果权重提升

This skill covers configuring score boosting to prioritize relevant code paths and deprioritize tests, docs, and vendor code.
本功能介绍如何配置分数权重提升,以优先展示相关代码路径,并降低测试文件、文档和第三方代码的优先级。

When to Use This Skill

使用场景

  • Prioritizing source code over tests
  • Penalizing vendor/third-party code
  • Boosting important directories
  • Customizing result ranking
  • 优先展示源代码而非测试文件
  • 降低第三方/供应商代码的优先级
  • 提升重要目录的权重
  • 自定义结果排序

What is Boosting?

什么是权重提升?

Boosting modifies search scores based on file paths:
Original score: 0.85 (src/auth.go)
Bonus (+10%):   0.935

Original score: 0.85 (tests/auth_test.go)
Penalty (-50%): 0.425
This ensures production code ranks higher than tests with similar content.
权重提升会根据文件路径修改搜索分数:
Original score: 0.85 (src/auth.go)
Bonus (+10%):   0.935

Original score: 0.85 (tests/auth_test.go)
Penalty (-50%): 0.425
这确保了生产代码比内容相似的测试文件排名更高。

Configuration

配置方法

Basic Configuration

基础配置

yaml
undefined
yaml
undefined

.grepai/config.yaml

.grepai/config.yaml

search: boost: enabled: true penalties: - pattern: /tests/ factor: 0.5 bonuses: - pattern: /src/ factor: 1.1
undefined
search: boost: enabled: true penalties: - pattern: /tests/ factor: 0.5 bonuses: - pattern: /src/ factor: 1.1
undefined

Full Configuration

完整配置

yaml
search:
  boost:
    enabled: true

    # Reduce scores (factor < 1.0)
    penalties:
      # Test files
      - pattern: /tests/
        factor: 0.5
      - pattern: /__tests__/
        factor: 0.5
      - pattern: _test.
        factor: 0.5
      - pattern: .spec.
        factor: 0.5
      - pattern: .test.
        factor: 0.5

      # Documentation
      - pattern: /docs/
        factor: 0.6
      - pattern: /documentation/
        factor: 0.6

      # Vendor/third-party
      - pattern: /vendor/
        factor: 0.3
      - pattern: /node_modules/
        factor: 0.3
      - pattern: /third_party/
        factor: 0.3

      # Generated code
      - pattern: /generated/
        factor: 0.4
      - pattern: .gen.
        factor: 0.4
      - pattern: .pb.go
        factor: 0.4

      # Examples and samples
      - pattern: /examples/
        factor: 0.7
      - pattern: /samples/
        factor: 0.7

    # Increase scores (factor > 1.0)
    bonuses:
      # Core source code
      - pattern: /src/
        factor: 1.1
      - pattern: /lib/
        factor: 1.1
      - pattern: /app/
        factor: 1.1
      - pattern: /core/
        factor: 1.2
      - pattern: /internal/
        factor: 1.1

      # Important directories
      - pattern: /services/
        factor: 1.1
      - pattern: /handlers/
        factor: 1.1
      - pattern: /controllers/
        factor: 1.1
yaml
search:
  boost:
    enabled: true

    # 降低分数(因子 < 1.0)
    penalties:
      # 测试文件
      - pattern: /tests/
        factor: 0.5
      - pattern: /__tests__/
        factor: 0.5
      - pattern: _test.
        factor: 0.5
      - pattern: .spec.
        factor: 0.5
      - pattern: .test.
        factor: 0.5

      # 文档
      - pattern: /docs/
        factor: 0.6
      - pattern: /documentation/
        factor: 0.6

      # 第三方/供应商代码
      - pattern: /vendor/
        factor: 0.3
      - pattern: /node_modules/
        factor: 0.3
      - pattern: /third_party/
        factor: 0.3

      # 自动生成代码
      - pattern: /generated/
        factor: 0.4
      - pattern: .gen.
        factor: 0.4
      - pattern: .pb.go
        factor: 0.4

      # 示例代码
      - pattern: /examples/
        factor: 0.7
      - pattern: /samples/
        factor: 0.7

    # 提高分数(因子 > 1.0)
    bonuses:
      # 核心源代码
      - pattern: /src/
        factor: 1.1
      - pattern: /lib/
        factor: 1.1
      - pattern: /app/
        factor: 1.1
      - pattern: /core/
        factor: 1.2
      - pattern: /internal/
        factor: 1.1

      # 重要目录
      - pattern: /services/
        factor: 1.1
      - pattern: /handlers/
        factor: 1.1
      - pattern: /controllers/
        factor: 1.1

How Factors Work

权重因子的作用

FactorEffectUse Case
0.370% reductionStrong penalty (vendor)
0.550% reductionModerate penalty (tests)
0.730% reductionMild penalty (examples)
1.0No changeNeutral
1.110% increaseMild boost (src)
1.220% increaseModerate boost (core)
1.550% increaseStrong boost
权重因子效果使用场景
0.3降低70%权重强惩罚(第三方依赖)
0.5降低50%权重中等惩罚(测试文件)
0.7降低30%权重轻度惩罚(示例代码)
1.0无变化中性
1.1提高10%权重轻度提升(源代码目录)
1.2提高20%权重中等提升(核心代码)
1.5提高50%权重强提升

Pattern Matching

路径匹配规则

Patterns match against the full file path:
/project/src/auth/middleware.go
         ^^^^
         Matches "/src/" pattern
匹配规则针对完整文件路径生效:
/project/src/auth/middleware.go
         ^^^^
         匹配 "/src/" 规则

Pattern Types

匹配规则类型

PatternMatchesDoesn't Match
/tests/
src/tests/auth.go
tests.go
_test.
auth_test.go
test_auth.go
.spec.
auth.spec.ts
spec/auth.ts
/src/
project/src/main.go
resource/file.go
规则匹配示例不匹配示例
/tests/
src/tests/auth.go
tests.go
_test.
auth_test.go
test_auth.go
.spec.
auth.spec.ts
spec/auth.ts
/src/
project/src/main.go
resource/file.go

Effect on Rankings

对排序结果的影响

Without Boosting

未启用权重提升时

Score: 0.85 | tests/auth_test.go:10-30
Score: 0.82 | src/auth/middleware.go:15-45
Score: 0.80 | src/auth/jwt.go:23-55
Score: 0.85 | tests/auth_test.go:10-30
Score: 0.82 | src/auth/middleware.go:15-45
Score: 0.80 | src/auth/jwt.go:23-55

With Boosting

启用权重提升后

yaml
penalties:
  - pattern: /tests/
    factor: 0.5
bonuses:
  - pattern: /src/
    factor: 1.1
Score: 0.90 | src/auth/middleware.go:15-45  (0.82 × 1.1)
Score: 0.88 | src/auth/jwt.go:23-55        (0.80 × 1.1)
Score: 0.43 | tests/auth_test.go:10-30     (0.85 × 0.5)
yaml
penalties:
  - pattern: /tests/
    factor: 0.5
bonuses:
  - pattern: /src/
    factor: 1.1
Score: 0.90 | src/auth/middleware.go:15-45  (0.82 × 1.1)
Score: 0.88 | src/auth/jwt.go:23-55        (0.80 × 1.1)
Score: 0.43 | tests/auth_test.go:10-30     (0.85 × 0.5)

Common Configurations

常见配置示例

Standard (Recommended)

标准配置(推荐)

yaml
search:
  boost:
    enabled: true
    penalties:
      - pattern: /tests/
        factor: 0.5
      - pattern: _test.
        factor: 0.5
      - pattern: .spec.
        factor: 0.5
      - pattern: /vendor/
        factor: 0.3
      - pattern: /docs/
        factor: 0.6
    bonuses:
      - pattern: /src/
        factor: 1.1
      - pattern: /lib/
        factor: 1.1
yaml
search:
  boost:
    enabled: true
    penalties:
      - pattern: /tests/
        factor: 0.5
      - pattern: _test.
        factor: 0.5
      - pattern: .spec.
        factor: 0.5
      - pattern: /vendor/
        factor: 0.3
      - pattern: /docs/
        factor: 0.6
    bonuses:
      - pattern: /src/
        factor: 1.1
      - pattern: /lib/
        factor: 1.1

Frontend Project

前端项目配置

yaml
search:
  boost:
    enabled: true
    penalties:
      - pattern: /__tests__/
        factor: 0.5
      - pattern: .test.
        factor: 0.5
      - pattern: .spec.
        factor: 0.5
      - pattern: /node_modules/
        factor: 0.3
      - pattern: .stories.
        factor: 0.6
      - pattern: /storybook/
        factor: 0.6
    bonuses:
      - pattern: /src/
        factor: 1.1
      - pattern: /components/
        factor: 1.1
      - pattern: /hooks/
        factor: 1.1
yaml
search:
  boost:
    enabled: true
    penalties:
      - pattern: /__tests__/
        factor: 0.5
      - pattern: .test.
        factor: 0.5
      - pattern: .spec.
        factor: 0.5
      - pattern: /node_modules/
        factor: 0.3
      - pattern: .stories.
        factor: 0.6
      - pattern: /storybook/
        factor: 0.6
    bonuses:
      - pattern: /src/
        factor: 1.1
      - pattern: /components/
        factor: 1.1
      - pattern: /hooks/
        factor: 1.1

Go Project

Go项目配置

yaml
search:
  boost:
    enabled: true
    penalties:
      - pattern: _test.go
        factor: 0.5
      - pattern: _mock.go
        factor: 0.5
      - pattern: /testdata/
        factor: 0.5
      - pattern: /vendor/
        factor: 0.3
      - pattern: .pb.go
        factor: 0.4
    bonuses:
      - pattern: /internal/
        factor: 1.1
      - pattern: /cmd/
        factor: 1.1
      - pattern: /pkg/
        factor: 1.1
yaml
search:
  boost:
    enabled: true
    penalties:
      - pattern: _test.go
        factor: 0.5
      - pattern: _mock.go
        factor: 0.5
      - pattern: /testdata/
        factor: 0.5
      - pattern: /vendor/
        factor: 0.3
      - pattern: .pb.go
        factor: 0.4
    bonuses:
      - pattern: /internal/
        factor: 1.1
      - pattern: /cmd/
        factor: 1.1
      - pattern: /pkg/
        factor: 1.1

Python Project

Python项目配置

yaml
search:
  boost:
    enabled: true
    penalties:
      - pattern: /tests/
        factor: 0.5
      - pattern: test_
        factor: 0.5
      - pattern: _test.py
        factor: 0.5
      - pattern: /conftest
        factor: 0.5
      - pattern: /fixtures/
        factor: 0.6
    bonuses:
      - pattern: /src/
        factor: 1.1
      - pattern: /app/
        factor: 1.1
      - pattern: /core/
        factor: 1.2
yaml
search:
  boost:
    enabled: true
    penalties:
      - pattern: /tests/
        factor: 0.5
      - pattern: test_
        factor: 0.5
      - pattern: _test.py
        factor: 0.5
      - pattern: /conftest
        factor: 0.5
      - pattern: /fixtures/
        factor: 0.6
    bonuses:
      - pattern: /src/
        factor: 1.1
      - pattern: /app/
        factor: 1.1
      - pattern: /core/
        factor: 1.2

Monorepo

单体仓库配置

yaml
search:
  boost:
    enabled: true
    penalties:
      - pattern: /tests/
        factor: 0.5
      - pattern: _test.
        factor: 0.5
      - pattern: /packages/deprecated/
        factor: 0.3
      - pattern: /packages/legacy/
        factor: 0.4
    bonuses:
      - pattern: /packages/core/
        factor: 1.2
      - pattern: /packages/api/
        factor: 1.1
      - pattern: /packages/shared/
        factor: 1.1
yaml
search:
  boost:
    enabled: true
    penalties:
      - pattern: /tests/
        factor: 0.5
      - pattern: _test.
        factor: 0.5
      - pattern: /packages/deprecated/
        factor: 0.3
      - pattern: /packages/legacy/
        factor: 0.4
    bonuses:
      - pattern: /packages/core/
        factor: 1.2
      - pattern: /packages/api/
        factor: 1.1
      - pattern: /packages/shared/
        factor: 1.1

Disabling Boosting

关闭权重提升

To disable boosting entirely:
yaml
search:
  boost:
    enabled: false
Or remove the boost section from config.
要完全关闭权重提升功能:
yaml
search:
  boost:
    enabled: false
或者直接从配置文件中移除boost节点。

Boosting vs Ignoring

权重提升与忽略的区别

ApproachEffectUse Case
IgnoreCompletely excludedDependencies, build output
PenaltyStill searchable, lower rankTests, docs, examples
NeutralDefault rankingRegular source code
BonusHigher rankCore business logic
方式效果使用场景
忽略完全排除在搜索结果外依赖包、构建输出
惩罚仍可被搜索到,但排名降低测试文件、文档、示例代码
中性默认排序常规源代码
奖励排名提升核心业务逻辑

When to Ignore vs Penalize

何时使用忽略 vs 惩罚

  • Ignore: Files you NEVER want to search (
    node_modules
    ,
    .git
    )
  • Penalize: Files you RARELY want but might need (
    tests
    ,
    docs
    )
  • 忽略:你永远不想搜索到的文件(
    node_modules
    ,
    .git
  • 惩罚:你很少需要但偶尔可能用到的文件(测试文件、文档)

Testing Your Configuration

测试你的配置

After configuring boosting:
bash
undefined
完成配置后:
bash
undefined

Search and observe rankings

执行搜索并观察排序结果

grepai search "authentication"
grepai search "authentication"

Check if tests are properly deprioritized

检查测试文件是否被正确降权

grepai search "test authentication" # Should still find tests, but ranked lower
undefined
grepai search "test authentication" # 仍能找到测试文件,但排名会更低
undefined

Best Practices

最佳实践

  1. Start with penalties: Deprioritize tests/vendor first
  2. Add bonuses sparingly: Only for truly important paths
  3. Test with real queries: Verify results make sense
  4. Don't over-penalize: 0.5 is usually enough for tests
  5. Document your choices: Add comments in config
  1. 先配置惩罚规则:优先降低测试文件/第三方依赖的优先级
  2. 谨慎添加奖励规则:仅对真正重要的路径使用
  3. 用真实查询测试:验证结果符合预期
  4. 不要过度惩罚:测试文件使用0.5的因子通常足够
  5. 记录配置原因:在配置文件中添加注释说明

Common Issues

常见问题

Problem: Tests always show up first ✅ Solution: Add penalty patterns for your test naming convention
Problem: Can't find code in penalized paths ✅ Solution: Penalties reduce rank, don't hide. Use ignore for complete exclusion.
Problem: Scores above 1.0 seem wrong ✅ Solution: Bonuses can push scores above 1.0; this is normal
Problem: Pattern not matching ✅ Solution: Check that pattern appears in full path (use
/tests/
not just
tests
)
问题:测试文件始终排在最前面 ✅ 解决方案:添加符合你的测试文件命名规范的惩罚规则
问题:无法找到被惩罚路径中的代码 ✅ 解决方案:惩罚仅降低排名,不会隐藏内容。如需完全排除请使用忽略规则。
问题:分数超过1.0看起来有问题 ✅ 解决方案:奖励规则会使分数超过1.0,这是正常现象
问题:规则不匹配 ✅ 解决方案:检查规则是否出现在完整文件路径中(例如使用
/tests/
而非仅
tests

Output Format

输出格式

Boosting configuration status:
✅ Search Boosting Configured

   Status: Enabled

   Penalties (5):
   - /tests/      → 0.5 (50% reduction)
   - _test.       → 0.5
   - .spec.       → 0.5
   - /vendor/     → 0.3 (70% reduction)
   - /docs/       → 0.6

   Bonuses (3):
   - /src/        → 1.1 (10% boost)
   - /lib/        → 1.1
   - /core/       → 1.2 (20% boost)

   Effect: Source code ranks higher than tests with similar content
权重提升配置状态:
✅ Search Boosting Configured

   Status: Enabled

   Penalties (5):
   - /tests/      → 0.5 (50% reduction)
   - _test.       → 0.5
   - .spec.       → 0.5
   - /vendor/     → 0.3 (70% reduction)
   - /docs/       → 0.6

   Bonuses (3):
   - /src/        → 1.1 (10% boost)
   - /lib/        → 1.1
   - /core/       → 1.2 (20% boost)

   Effect: Source code ranks higher than tests with similar content