search: add attribute substring search

Change-Id: I3b30541c43b5fba84491b98ed73d34a64465c24e
This commit is contained in:
Brad Fitzpatrick 2014-06-20 12:10:20 -07:00
parent a57da00936
commit bf3d86e471
2 changed files with 27 additions and 3 deletions

View File

@ -233,7 +233,8 @@ func newAttribute() keyword {
func (a attribute) Description() string {
return "match on attribute. Use attr:foo:bar to match nodes having their foo\n" +
"attribute set to bar."
"attribute set to bar or attr:foo:~bar to do a substring\n" +
"case-insensitive search for 'bar' in attribute foo"
}
func (a attribute) Predicate(ctx *context.Context, args []string) (*Constraint, error) {
@ -244,6 +245,14 @@ func (a attribute) Predicate(ctx *context.Context, args []string) (*Constraint,
Value: args[1],
},
}
if strings.HasPrefix(args[1], "~") {
// Substring. Hack. Figure out better way to do this.
c.Permanode.Value = ""
c.Permanode.ValueMatches = &StringConstraint{
Contains: args[1][1:],
CaseInsensitive: true,
}
}
return c, nil
}
@ -539,8 +548,8 @@ func newHasLocation() keyword {
}
func (h hasLocation) Description() string {
return "matches images and permanodes that have a location (GPSLatitude and GPSLongitude can be\n" +
"retrieved from the image's EXIF tags)."
return "matches images and permanodes that have a location (GPSLatitude\n" +
"and GPSLongitude can be retrieved from the image's EXIF tags)."
}
func (h hasLocation) Predicate(ctx *context.Context, args []string) (*Constraint, error) {

View File

@ -190,6 +190,21 @@ var keywordTests = []keywordTestcase{
want: attrfoobarC,
},
{
object: newAttribute(),
args: []string{"foo", "~bar"},
want: &Constraint{
Permanode: &PermanodeConstraint{
Attr: "foo",
ValueMatches: &StringConstraint{
Contains: "bar",
CaseInsensitive: true,
},
SkipHidden: true,
},
},
},
{
object: newChildrenOf(),
args: []string{"foo"},