dartora

Points

Points encapsulates positive and negative scores and provides arithmetic and comparison operations. It is used by search scoring to accumulate points for matched and forbidden words and to calculate the final score via a modifier based on occurrences.

Abstract API

Points is an abstract class with the following getters:

Factories

factory Points.from({ required int positive, required int negative, required int occurrences, required int modifier })
factory Points.all(int value)
factory Points.empty()

These factories return UnmodifiablePoints instances with the specified values. Points.all(value) sets all fields (positive, negative, occurrences, modifier) to the same value. Points.empty() sets all fields to zero.

Operators

Points defines arithmetic operators to combine two points objects:

Implementations

UnmodifiablePoints

An immutable implementation of Points. Fields are set at construction and cannot be changed. Used by SearchQueryComparison to store final scores.

ModifiablePoints

A mutable implementation used internally when building up scores. Fields start at zero and can be incremented:

ModifiablePoints implements the abstract getters by returning internal fields.

When computing a SearchQueryComparison, the algorithm uses ModifiablePoints to accumulate positive and negative scores and then converts it to UnmodifiablePoints via Points.from(...). This ensures that final scores are immutable but can be combined via + when comparing against multiple fields.