Skip to content

Refactor: Extract magic numbers and improve logging in SearchService #232

@DrunkOnJava

Description

@DrunkOnJava

Background

PR #217 successfully implemented item name suggestions in SearchService, but code review identified several improvements that should be made:

Tasks

  • Extract magic numbers as named constants:
    • Base score (0.8)
    • Position penalty (0.02)
    • Minimum score (0.1)
  • Replace print statements with proper logging using os_log or logging framework
  • Fix test brittleness by avoiding hardcoded expectation counts
  • Clarify misleading comments about item limits

Suggested Implementation

private enum ScoringConstants {
    static let baseScore = 0.8
    static let positionPenalty = 0.02
    static let minimumScore = 0.1
}

// Use os_log for error logging
import os.log
os_log("Error fetching suggestions: %{public}@", log: .default, type: .error, String(describing: error))

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpriority-lowLow prioritytech-debtTechnical debt that needs addressing

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions