In Files

YALTools::YaViewDocs

Description

YALTools::YaViewDocs is designed to handle huge amount of documents using View API.

Restrictions

To improve performance, the view definition should include the “_count” reduce function or “_sum” function with emit(x, 1).

  {
    "xxx": {
       "map": "xxxx",
       "reduce": "_count"
    }
  }
     or
  {
    "xxx": {
       "map": "... emit(xxx, 1); ...",
       "reduce": "_sum"
    }
  }

Otherwise, the max_numrows method cannot return the correct value. So, the pagination cannot work well.

In this case, please use the YALTools::YaDocs::get_all(options, limit) method instead.

Please refer the unittest script, unittest/ut.yalt.yaview.rb.

Usage

   view = YALTools::YaViewDocs.new(@couch, @dbname, @designname, @viewname)
   view.each(opts, @opts[:page], @opts[:unit]) do |rows, skip, page, max_page, max_rows|
     rows.each do |i|  ## rows is an instance of YaJsonRows
       puts i.to_json
     end
   end

Public Class Methods

new(couch, dbname, design_name, view_name) click to toggle source
     # File yalt/yaview.rb, line 443
443:     def initialize(couch, dbname, design_name, view_name)
444:       @couch = couch
445:       @dbname = dbname
446:       @debug = @couch.debug if @couch.respond_to?("debug")
447:       
448:       @design_name = design_name
449:       @view_name = view_name
450:       
451:       @default_query_options = { "reduce" => "false", "descending" => "false", "include_docs" => "true" }
452:     end

Private Instance Methods

gen_view_uri(opts={}) click to toggle source
     # File yalt/yaview.rb, line 455
455:     def gen_view_uri(opts={})
456:       uri = format("/%s/_design/%s/_view/%s", @dbname, @design_name, @view_name)
457:       return gen_uri_with_options(uri, opts)
458:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.