diff --git a/pkg/search/query.go b/pkg/search/query.go index 5b72dd2c6..5d0b3dfa5 100644 --- a/pkg/search/query.go +++ b/pkg/search/query.go @@ -99,8 +99,8 @@ type Constraint struct { File *FileConstraint Dir *DirConstraint - Claim *ClaimConstraint `json:"claim"` - BlobSize *BlobSizeConstraint `json:"blobSize"` + Claim *ClaimConstraint `json:"claim"` + BlobSize *IntConstraint `json:"blobSize"` Permanode *PermanodeConstraint `json:"permanode"` } @@ -145,7 +145,7 @@ type IntConstraint struct { ZeroMax bool } -func (c *IntConstraint) matchesInt(v int64) bool { +func (c *IntConstraint) intMatches(v int64) bool { if (c.Min != 0 || c.ZeroMin) && v < c.Min { return false } @@ -212,11 +212,6 @@ type LogicalConstraint struct { B *Constraint `json:"b"` // only valid if Op == "not" } -type BlobSizeConstraint struct { - Min int `json:"min"` // inclusive - Max int `json:"max"` // inclusive. if zero, ignored. -} - // PermanodeConstraint matches permanodes. type PermanodeConstraint struct { // At specifies the time at which to pretend we're resolving attributes. @@ -358,13 +353,7 @@ func (c *Constraint) blobMatches(s *search, br blob.Ref, blobMeta BlobMeta) (boo } if bs := c.BlobSize; bs != nil { addCond(func(s *search, br blob.Ref, bm BlobMeta) (bool, error) { - if bm.Size < bs.Min { - return false, nil - } - if bs.Max > 0 && bm.Size > bs.Max { - return false, nil - } - return true, nil + return bs.intMatches(int64(bm.Size)), nil }) } diff --git a/pkg/search/query_test.go b/pkg/search/query_test.go index 3729e682a..5e68f9f52 100644 --- a/pkg/search/query_test.go +++ b/pkg/search/query_test.go @@ -103,7 +103,7 @@ func TestQueryBlobSize(t *testing.T) { sq := &SearchQuery{ Constraint: &Constraint{ - BlobSize: &BlobSizeConstraint{ + BlobSize: &IntConstraint{ Min: 4 << 10, Max: 6 << 10, }, @@ -188,8 +188,8 @@ func TestQueryLogicalAnd(t *testing.T) { BlobRefPrefix: "sha1-0", }, B: &Constraint{ - BlobSize: &BlobSizeConstraint{ - Max: len("foo"), // excludes "bar.." + BlobSize: &IntConstraint{ + Max: int64(len("foo")), // excludes "bar.." }, }, },