mirror of https://github.com/perkeep/perkeep.git
search: ditch BlobSizeConstraint, use IntConstraint instead
Change-Id: I99bece643841feab777175479743b3bd1fc421b8
This commit is contained in:
parent
1e627ce7c3
commit
17a9d061a0
|
@ -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
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
@ -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.."
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue