本文整理汇总了Golang中github.com/araddon/gou.NewJsonHelper函数的典型用法代码示例。如果您正苦于以下问题:Golang NewJsonHelper函数的具体用法?Golang NewJsonHelper怎么用?Golang NewJsonHelper使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewJsonHelper函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestSearchSortOrder
func TestSearchSortOrder(t *testing.T) {
c := NewConn()
// ok, now lets try sorting by repository watchers descending
qry := Search("github").Pretty().Query(
Query().All(),
).Sort(
Sort("repository.watchers").Desc(),
)
out, _ := qry.Result(c)
// how many different docs used the word "add", during entire time range
expectedDocs := 10
expectedTotal := 8084
assert.T(t, out.Hits.Len() == expectedDocs, fmt.Sprintf("Should have %v docs %v", expectedDocs, out.Hits.Len()))
assert.T(t, out.Hits.Total == expectedTotal, fmt.Sprintf("Should have %v total= %v", expectedTotal, out.Hits.Total))
b, err := out.Hits.Hits[0].Source.MarshalJSON()
assert.T(t, err == nil, fmt.Sprintf("Should not have returned an error: %v", err))
h1 := gou.NewJsonHelper(b)
assert.T(t, h1.Int("repository.watchers") == 41377,
fmt.Sprintf("Should have 41377 watchers= %v", h1.Int("repository.watchers")))
// ascending
out, _ = Search("github").Pretty().Query(
Query().All(),
).Sort(
Sort("repository.watchers"),
).Result(c)
// how many different docs used the word "add", during entire time range
assert.T(t, out.Hits.Len() == expectedDocs, fmt.Sprintf("Should have %v docs %v", expectedDocs, out.Hits.Len()))
assert.T(t, out.Hits.Total == expectedTotal, fmt.Sprintf("Should have %v total got %v", expectedTotal, out.Hits.Total))
b, err = out.Hits.Hits[0].Source.MarshalJSON()
assert.T(t, err == nil, fmt.Sprintf("Should not have returned an error: %v", err))
h2 := gou.NewJsonHelper(b)
assert.T(t, h2.Int("repository.watchers") == 0,
fmt.Sprintf("Should have 0 watchers= %v", h2.Int("repository.watchers")))
// sort descending with search
out, _ = Search("github").Pretty().Size("5").Query(
Query().Search("python"),
).Sort(
Sort("repository.watchers").Desc(),
).Result(c)
// how many different docs used the word "add", during entire time range
expectedDocs = 5
expectedTotal = 734
assert.T(t, out.Hits.Len() == expectedDocs, fmt.Sprintf("Should have %v docs %v", expectedDocs, out.Hits.Len()))
assert.T(t, out.Hits.Total == expectedTotal, fmt.Sprintf("Should have %v total got %v", expectedTotal, out.Hits.Total))
b, err = out.Hits.Hits[0].Source.MarshalJSON()
assert.T(t, err == nil, fmt.Sprintf("Should not have returned an error: %v", err))
h3 := gou.NewJsonHelper(b)
watchers := 8659
assert.T(t, h3.Int("repository.watchers") == watchers,
fmt.Sprintf("Should have %v watchers, got %v", watchers, h3.Int("repository.watchers")))
}
开发者ID:harlow,项目名称:places,代码行数:58,代码来源:searchsearch_test.go
示例2: TestSearchFacetRange
func TestSearchFacetRange(t *testing.T) {
c := NewConn()
// ok, now lets try facet but on actor field with a range
qry := Search("github").Pretty().Facet(
Facet().Fields("actor").Size("500"),
).Query(
Query().Search("add"),
)
out, err := qry.Result(c)
assert.T(t, out != nil && err == nil, t, "Should have output")
if out == nil {
t.Fail()
return
}
//log.Println(string(out.Facets))
h := gou.NewJsonHelper(out.Facets)
expectedActorTotal := 521
// how many different docs used the word "add", during entire time range
assert.T(t, h.Int("actor.total") == expectedActorTotal, fmt.Sprintf("Should have %v results %v", expectedActorTotal, h.Int("actor.total")))
// make sure size worked
expectedTerms := 366
assert.T(t, len(h.List("actor.terms")) == expectedTerms,
fmt.Sprintf("Should have %v unique userids, %v", expectedTerms, len(h.List("actor.terms"))))
// ok, repeat but with a range showing different results
qry = Search("github").Pretty().Facet(
Facet().Fields("actor").Size("500"),
).Query(
Query().Range(
Range().Field("created_at").From("2012-12-10T15:00:00-08:00").To("2012-12-10T15:10:00-08:00"),
).Search("add"),
)
out, err = qry.Result(c)
assert.T(t, out != nil && err == nil, t, "Should have output")
if out == nil {
t.Fail()
return
}
//log.Println(string(out.Facets))
h = gou.NewJsonHelper(out.Facets)
// how many different events used the word "add", during time range?
expectedActorTotal = 97
expectedTerms = 71
assert.T(t, h.Int("actor.total") == expectedActorTotal, fmt.Sprintf("Should have %v results %v", expectedActorTotal, h.Int("actor.total")))
// make sure size worked
assert.T(t, len(h.List("actor.terms")) == expectedTerms,
fmt.Sprintf("Should have %v event types, %v", expectedTerms, len(h.List("actor.terms"))))
}
开发者ID:harlow,项目名称:places,代码行数:52,代码来源:searchsearch_test.go
示例3: TestSearchSortOrder
func TestSearchSortOrder(t *testing.T) {
// ok, now lets try sorting by repository watchers descending
qry := Search("github").Pretty().Query(
Query().All(),
).Sort(
Sort("repository.watchers").Desc(),
)
out, _ := qry.Result()
// how many different docs used the word "add", during entire time range
assert.T(t, out.Hits.Len() == 10, fmt.Sprintf("Should have 10 docs %v", out.Hits.Len()))
assert.T(t, out.Hits.Total == 8084, fmt.Sprintf("Should have 8084 total= %v", out.Hits.Total))
h1 := gou.NewJsonHelper(out.Hits.Hits[0].Source)
assert.T(t, h1.Int("repository.watchers") == 41377,
fmt.Sprintf("Should have 41377 watchers= %v", h1.Int("repository.watchers")))
// ascending
out, _ = Search("github").Pretty().Query(
Query().All(),
).Sort(
Sort("repository.watchers"),
).Result()
// how many different docs used the word "add", during entire time range
assert.T(t, out.Hits.Len() == 10, fmt.Sprintf("Should have 10 docs %v", out.Hits.Len()))
assert.T(t, out.Hits.Total == 8084, fmt.Sprintf("Should have 8084 total= %v", out.Hits.Total))
h2 := gou.NewJsonHelper(out.Hits.Hits[0].Source)
assert.T(t, h2.Int("repository.watchers") == 0,
fmt.Sprintf("Should have 0 watchers= %v", h2.Int("repository.watchers")))
// sort descending with search
out, _ = Search("github").Pretty().Size("5").Query(
Query().Search("python"),
).Sort(
Sort("repository.watchers").Desc(),
).Result()
//log.Println(out)
//log.Println(err)
// how many different docs used the word "add", during entire time range
assert.T(t, out.Hits.Len() == 5, fmt.Sprintf("Should have 5 docs %v", out.Hits.Len()))
assert.T(t, out.Hits.Total == 734, fmt.Sprintf("Should have 734 total= %v", out.Hits.Total))
h3 := gou.NewJsonHelper(out.Hits.Hits[0].Source)
assert.T(t, h3.Int("repository.watchers") == 8659,
fmt.Sprintf("Should have 8659 watchers= %v", h3.Int("repository.watchers")))
}
开发者ID:malysoun,项目名称:elastigo,代码行数:46,代码来源:search_test.go
示例4: TestSearchFacetRange
func TestSearchFacetRange(t *testing.T) {
// ok, now lets try facet but on actor field with a range
qry := Search("github").Pretty().Facet(
Facet().Fields("actor").Size("500"),
).Query(
Query().Search("add"),
)
out, err := qry.Result()
u.Assert(out != nil && err == nil, t, "Should have output")
if out == nil {
t.Fail()
return
}
//log.Println(string(out.Facets))
h := u.NewJsonHelper(out.Facets)
// how many different docs used the word "add", during entire time range
u.Assert(h.Int("actor.total") == 521, t, "Should have 521 results %v", h.Int("actor.total"))
// make sure size worked
u.Assert(len(h.List("actor.terms")) == 366, t, "Should have 366 unique userids, %v", len(h.List("actor.terms")))
// ok, repeat but with a range showing different results
qry = Search("github").Pretty().Facet(
Facet().Fields("actor").Size("500"),
).Query(
Query().Range(
Range().Field("created_at").From("2012-12-10T15:00:00-08:00").To("2012-12-10T15:10:00-08:00"),
).Search("add"),
)
out, err = qry.Result()
u.Assert(out != nil && err == nil, t, "Should have output")
if out == nil {
t.Fail()
return
}
//log.Println(string(out.Facets))
h = u.NewJsonHelper(out.Facets)
// how many different events used the word "add", during time range?
u.Assert(h.Int("actor.total") == 97, t, "Should have 97 results %v", h.Int("actor.total"))
// make sure size worked
u.Assert(len(h.List("actor.terms")) == 71, t, "Should have 71 event types, %v", len(h.List("actor.terms")))
}
开发者ID:hailocab,项目名称:elastigo,代码行数:44,代码来源:search_test.go
示例5: TestFacetRegex
func TestFacetRegex(t *testing.T) {
// This is a possible solution for auto-complete
out, _ := Search("github").Size("0").Facet(
Facet().Regex("repository.name", "no.*").Size("8"),
).Result()
if out == nil || &out.Hits == nil {
t.Fail()
return
}
//Debug(string(out.Facets))
fh := gou.NewJsonHelper([]byte(out.Facets))
facets := fh.Helpers("/repository.name/terms")
assert.T(t, len(facets) == 8, fmt.Sprintf("Should have 8? but was %v", len(facets)))
// for _, f := range facets {
// Debug(f)
// }
}
开发者ID:pombredanne,项目名称:vossibility-bulletin,代码行数:17,代码来源:facet_test.go
示例6: main
func main() {
flag.Parse()
goauthcon = &oauth.OAuthConsumer{
Service: "twitter",
RequestTokenURL: "https://api.twitter.com/oauth/request_token",
AccessTokenURL: "https://api.twitter.com/oauth/access_token",
AuthorizationURL: "https://api.twitter.com/oauth/authorize",
ConsumerKey: *ck,
ConsumerSecret: *cs,
CallBackURL: "oob",
}
s, rt, err := goauthcon.GetRequestAuthorizationURL()
if err != nil {
fmt.Println(err)
return
}
var pin string
fmt.Printf("Open %s In your browser.\n Allow access and then enter the PIN number\n", s)
fmt.Printf("PIN Number: ")
fmt.Scanln(&pin)
at := goauthcon.GetAccessToken(rt.Token, pin)
fmt.Printf("\n\n\ttoken=%s secret=%s \n\n\n", at.Token, at.Secret)
r, err := goauthcon.Get("https://api.twitter.com/1.1/account/verify_credentials.json", nil, at)
if err != nil {
fmt.Println(err)
return
}
if r != nil && r.Body != nil && r.StatusCode == 200 {
userData, _ := ioutil.ReadAll(r.Body)
if len(userData) > 0 {
jh := u.NewJsonHelper(userData)
fmt.Println(string(jh.PrettyJson()))
}
} else {
fmt.Println(r)
fmt.Println("Twitter verify failed")
}
}
开发者ID:araddon,项目名称:httpstream,代码行数:43,代码来源:main.go
示例7: TestFacetRegex
func TestFacetRegex(t *testing.T) {
c := NewTestConn()
PopulateTestDB(t, c)
defer TearDownTestDB(c)
Convey("Facted regex query", t, func() {
// This is a possible solution for auto-complete
out, err := Search("oilers").Size("0").Facet(
Facet().Regex("name", "[jk].*").Size("8"),
).Result(c)
So(err, ShouldBeNil)
So(out, ShouldNotBeNil)
// Debug(string(out.Facets))
fh := gou.NewJsonHelper([]byte(out.Facets))
facets := fh.Helpers("/name/terms")
So(err, ShouldBeNil)
So(facets, ShouldNotBeNil)
So(len(facets), ShouldEqual, 4)
})
}
开发者ID:pombredanne,项目名称:gollum-1,代码行数:23,代码来源:searchfacet_test.go
示例8: TestSearchFacetOne
func TestSearchFacetOne(t *testing.T) {
/*
A faceted search for what "type" of events there are
- since we are not specifying an elasticsearch type it searches all ()
{
"terms" : {
"_type" : "terms",
"missing" : 0,
"total" : 7561,
"other" : 0,
"terms" : [ {
"term" : "pushevent",
"count" : 4185
}, {
"term" : "createevent",
"count" : 786
}.....]
}
}
*/
qry := Search("github").Pretty().Facet(
Facet().Fields("type").Size("25"),
).Query(
Query().All(),
).Size("1")
out, err := qry.Result()
//log.Println(string(out.Facets))
//gou.Debug(out)
assert.T(t, out != nil && err == nil, "Should have output")
if out == nil {
t.Fail()
return
}
h := gou.NewJsonHelper(out.Facets)
assert.T(t, h.Int("type.total") == 8084, fmt.Sprintf("Should have 8084 results %v", h.Int("type.total")))
assert.T(t, len(h.List("type.terms")) == 16, fmt.Sprintf("Should have 16 event types, %v", len(h.List("type.terms"))))
// Now, lets try changing size to 10
qry.FacetVal.Size("10")
out, err = qry.Result()
h = gou.NewJsonHelper(out.Facets)
// still same doc count
assert.T(t, h.Int("type.total") == 8084, fmt.Sprintf("Should have 8084 results %v", h.Int("type.total")))
// make sure size worked
assert.T(t, len(h.List("type.terms")) == 10, fmt.Sprintf("Should have 10 event types, %v", len(h.List("type.terms"))))
// now, lets add a type (out of the 16)
out, _ = Search("github").Type("IssueCommentEvent").Pretty().Facet(
Facet().Fields("type").Size("25"),
).Query(
Query().All(),
).Result()
h = gou.NewJsonHelper(out.Facets)
//log.Println(string(out.Facets))
// still same doc count
assert.T(t, h.Int("type.total") == 685, fmt.Sprintf("Should have 685 results %v", h.Int("type.total")))
// we should only have one facettype because we limited to one type
assert.T(t, len(h.List("type.terms")) == 1, fmt.Sprintf("Should have 1 event types, %v", len(h.List("type.terms"))))
// now, add a second type (chained)
out, _ = Search("github").Type("IssueCommentEvent").Type("PushEvent").Pretty().Facet(
Facet().Fields("type").Size("25"),
).Query(
Query().All(),
).Result()
h = gou.NewJsonHelper(out.Facets)
//log.Println(string(out.Facets))
// still same doc count
assert.T(t, h.Int("type.total") == 4941, fmt.Sprintf("Should have 4941 results %v", h.Int("type.total")))
// make sure we now have 2 types
assert.T(t, len(h.List("type.terms")) == 2, fmt.Sprintf("Should have 2 event types, %v", len(h.List("type.terms"))))
//and instead of faceting on type, facet on userid
// now, add a second type (chained)
out, _ = Search("github").Type("IssueCommentEvent,PushEvent").Pretty().Facet(
Facet().Fields("actor").Size("500"),
).Query(
Query().All(),
).Result()
h = gou.NewJsonHelper(out.Facets)
// still same doc count
assert.T(t, h.Int("actor.total") == 5158, t, "Should have 5158 results %v", h.Int("actor.total"))
// make sure size worked
assert.T(t, len(h.List("actor.terms")) == 500, t, "Should have 500 users, %v", len(h.List("actor.terms")))
}
开发者ID:malysoun,项目名称:elastigo,代码行数:89,代码来源:search_test.go
示例9: TestSearch
func TestSearch(t *testing.T) {
c := NewTestConn()
PopulateTestDB(t, c)
defer TearDownTestDB(c)
Convey("Wildcard request query", t, func() {
qry := map[string]interface{}{
"query": map[string]interface{}{
"wildcard": map[string]string{"name": "*hu*"},
},
}
out, err := c.Search("oilers", "", nil, qry)
So(err, ShouldBeNil)
So(out, ShouldNotBeNil)
So(out.Hits, ShouldNotBeNil)
So(out.Hits.Total, ShouldEqual, 3)
})
Convey("Simple search", t, func() {
// searching without faceting
qry := Search("oilers").Pretty().Query(
Query().Search("dave"),
)
// how many different docs used the word "dave"
out, err := qry.Result(c)
So(err, ShouldBeNil)
So(out, ShouldNotBeNil)
So(out.Hits, ShouldNotBeNil)
So(out.Hits.Total, ShouldEqual, 2)
out, _ = Search("oilers").Search("dave").Result(c)
So(err, ShouldBeNil)
So(out, ShouldNotBeNil)
So(out.Hits, ShouldNotBeNil)
So(out.Hits.Total, ShouldEqual, 2)
})
Convey("URL Request query string", t, func() {
out, err := c.SearchUri("oilers", "", map[string]interface{}{"q": "pos:LW"})
So(err, ShouldBeNil)
So(out, ShouldNotBeNil)
So(out.Hits, ShouldNotBeNil)
So(out.Hits.Total, ShouldEqual, 3)
})
// A faceted search for what "type" of events there are
// - since we are not specifying an elasticsearch type it searches all ()
//
// {
// "terms" : {
// "_type" : "terms",
// "missing" : 0,
// "total" : 7561,
// "other" : 0,
// "terms" : [ {
// "term" : "pushevent",
// "count" : 4185
// }, {
// "term" : "createevent",
// "count" : 786
// }.....]
// }
// }
Convey("Facet search simple", t, func() {
qry := Search("oilers").Pretty().Facet(
Facet().Fields("teams").Size("4"),
).Query(
Query().All(),
).Size("1")
out, err := qry.Result(c)
So(err, ShouldBeNil)
So(out, ShouldNotBeNil)
h := gou.NewJsonHelper(out.Facets)
So(h.Int("teams.total"), ShouldEqual, 37)
So(h.Int("teams.missing"), ShouldEqual, 0)
So(len(h.List("teams.terms")), ShouldEqual, 4)
// change the size
qry.FacetVal.Size("20")
out, err = qry.Result(c)
So(err, ShouldBeNil)
So(out, ShouldNotBeNil)
h = gou.NewJsonHelper(out.Facets)
So(h.Int("teams.total"), ShouldEqual, 37)
So(len(h.List("teams.terms")), ShouldEqual, 11)
})
Convey("Facet search with type", t, func() {
//.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:gollum-1,代码行数:101,代码来源:searchsearch_test.go
注:本文中的github.com/araddon/gou.NewJsonHelper函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论