Exemple #1
0
func doAndSearchRequest(cluster *riak.Cluster) error {
	cmd, err := riak.NewSearchCommandBuilder().
		WithIndexName("famous").
		WithQuery("leader_b:true AND age_i:[30 TO *]").
		Build()
	if err != nil {
		return err
	}

	if err := cluster.Execute(cmd); err != nil {
		return err
	}

	return printDocs(cmd, "AND Search Documents:")
}
Exemple #2
0
func doSearchRequest(cluster *riak.Cluster) error {
	cmd, err := riak.NewSearchCommandBuilder().
		WithIndexName("famous").
		WithQuery("name_s:Lion*").
		Build()
	if err != nil {
		return err
	}

	if err := cluster.Execute(cmd); err != nil {
		return err
	}

	if err := printDocs(cmd, "Search Request Documents:"); err != nil {
		return err
	}

	sc := cmd.(*riak.SearchCommand)
	doc := sc.Response.Docs[0] // NB: SearchDoc struct type

	cmd, err = riak.NewFetchValueCommandBuilder().
		WithBucketType(doc.BucketType).
		WithBucket(doc.Bucket).
		WithKey(doc.Key).
		Build()
	if err != nil {
		return err
	}

	if err := cluster.Execute(cmd); err != nil {
		return err
	}

	fc := cmd.(*riak.FetchValueCommand)
	if json, jerr := json.MarshalIndent(fc.Response, "", "  "); jerr != nil {
		return jerr
	} else {
		fmt.Println(string(json))
	}

	return nil
}
Exemple #3
0
func doPaginatedSearchRequest(cluster *riak.Cluster) error {
	rowsPerPage := uint32(2)
	page := uint32(2)
	start := rowsPerPage * (page - uint32(1))

	cmd, err := riak.NewSearchCommandBuilder().
		WithIndexName("famous").
		WithQuery("*:*").
		WithStart(start).
		WithNumRows(rowsPerPage).
		Build()
	if err != nil {
		return err
	}

	if err := cluster.Execute(cmd); err != nil {
		return err
	}

	return printDocs(cmd, "Paginated Search Documents:")
}