feat: externalize filter configuration and add global structured logging and job reprocessing functionality

This commit is contained in:
2026-08-14 15:27:50 -07:00
parent 890469fed8
commit 5510e3ac82
17 changed files with 257 additions and 80 deletions
+8 -4
View File
@@ -1,6 +1,10 @@
package filter
import "context"
import (
"context"
"github.com/hireme/hireme/internal/db"
)
type FilterResult struct {
Keep bool
@@ -10,7 +14,7 @@ type FilterResult struct {
type JobFilter interface {
Name() string
Process(ctx context.Context, title, rawContent string) (FilterResult, error)
Process(ctx context.Context, job *db.RawJob) (FilterResult, error)
}
type FilterPipeline struct {
@@ -21,10 +25,10 @@ func NewPipeline(filters ...JobFilter) *FilterPipeline {
return &FilterPipeline{filters: filters}
}
func (p *FilterPipeline) Execute(ctx context.Context, title, rawContent string) (bool, float64, string) {
func (p *FilterPipeline) Execute(ctx context.Context, job *db.RawJob) (bool, float64, string) {
var totalScore float64
for _, f := range p.filters {
res, err := f.Process(ctx, title, rawContent)
res, err := f.Process(ctx, job)
if err != nil {
return false, 0, err.Error()
}
+6 -4
View File
@@ -3,6 +3,8 @@ package filter
import (
"context"
"testing"
"github.com/hireme/hireme/internal/db"
)
func TestHardKeywordFilter(t *testing.T) {
@@ -10,7 +12,7 @@ func TestHardKeywordFilter(t *testing.T) {
fk := NewHardKeywordFilter([]string{"DevOps", "No Sponsorship"})
// Should fail due to DevOps
res1, err := fk.Process(ctx, "Senior DevOps Engineer", "We build pipelines.")
res1, err := fk.Process(ctx, &db.RawJob{Title: "Senior DevOps Engineer", RawContent: "We build pipelines."})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
@@ -19,7 +21,7 @@ func TestHardKeywordFilter(t *testing.T) {
}
// Should pass
res2, err := fk.Process(ctx, "Senior Backend Engineer", "We build scalable APIs in Go.")
res2, err := fk.Process(ctx, &db.RawJob{Title: "Senior Backend Engineer", RawContent: "We build scalable APIs in Go."})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
@@ -39,7 +41,7 @@ func TestFilterPipeline(t *testing.T) {
pipeline := NewPipeline(hardFilter, scoringFilter)
// Test job 1: Unpaid job -> rejected by hard filter
keep1, score1, _ := pipeline.Execute(ctx, "Backend Intern", "Unpaid position working with Go.")
keep1, score1, _ := pipeline.Execute(ctx, &db.RawJob{Title: "Backend Intern", RawContent: "Unpaid position working with Go."})
if keep1 {
t.Errorf("expected job 1 to be filtered out, got keep=true")
}
@@ -48,7 +50,7 @@ func TestFilterPipeline(t *testing.T) {
}
// Test job 2: Qualified job -> passes both filters and accumulates score
keep2, score2, _ := pipeline.Execute(ctx, "Senior Go Backend Engineer", "Building high throughput services.")
keep2, score2, _ := pipeline.Execute(ctx, &db.RawJob{Title: "Senior Go Backend Engineer", RawContent: "Building high throughput services."})
if !keep2 {
t.Errorf("expected job 2 to pass filter pipeline, got keep=false")
}
+4 -2
View File
@@ -4,6 +4,8 @@ import (
"context"
"fmt"
"strings"
"github.com/hireme/hireme/internal/db"
)
type HardKeywordFilter struct {
@@ -26,8 +28,8 @@ func (f *HardKeywordFilter) Name() string {
return "HardKeywordFilter"
}
func (f *HardKeywordFilter) Process(ctx context.Context, title, rawContent string) (FilterResult, error) {
combined := strings.ToLower(title + " " + rawContent)
func (f *HardKeywordFilter) Process(ctx context.Context, job *db.RawJob) (FilterResult, error) {
combined := strings.ToLower(job.Title + " " + job.RawContent)
for _, kw := range f.Blacklist {
term := strings.ToLower(strings.TrimSpace(kw))
+6 -4
View File
@@ -4,6 +4,8 @@ import (
"context"
"fmt"
"strings"
"github.com/hireme/hireme/internal/db"
)
type KeywordWeight struct {
@@ -38,14 +40,14 @@ func (s *ScoringFilter) Name() string {
return "ScoringFilter"
}
func (s *ScoringFilter) Process(ctx context.Context, title, rawContent string) (FilterResult, error) {
combined := strings.ToLower(title + " " + rawContent)
func (f *ScoringFilter) Process(ctx context.Context, job *db.RawJob) (FilterResult, error) {
combinedLower := strings.ToLower(job.Title + " " + job.RawContent)
var totalScore float64
var matched []string
for _, kw := range s.Weights {
for _, kw := range f.Weights {
term := strings.ToLower(strings.TrimSpace(kw.Keyword))
if term != "" && strings.Contains(combined, term) {
if term != "" && strings.Contains(combinedLower, term) {
totalScore += kw.Weight
matched = append(matched, kw.Keyword)
}