File: test-solr_stats.r

package info (click to toggle)
r-cran-solrium 1.1.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,132 kB
  • sloc: xml: 374; sh: 13; makefile: 2
file content (77 lines) | stat: -rw-r--r-- 2,556 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
context("solr_stats")

test_that("solr_stats works", {
  skip_on_cran()

  a <- conn_plos$stats(params = list(q='science', stats.field='counter_total_all'), raw=TRUE)
  Sys.sleep(2)
  b <- conn_plos$stats(params = list(q='ecology', stats.field=c('counter_total_all','alm_twitterCount'),
                  stats.facet=c('journal','volume')))
  Sys.sleep(2)
  c <- conn_plos$stats(params = list(q='ecology', stats.field=c('counter_total_all','alm_twitterCount'),
                  stats.facet=c('journal','volume')), raw=TRUE)
  Sys.sleep(2)
  d <- solr_parse(c) # list
  e <- solr_parse(c, 'df') # data.frame

  # correct dimenions
  expect_equal(length(a), 1)
  expect_equal(length(b), 2)
  expect_equal(nrow(b$data), 2)
  expect_equal(NCOL(b$facet$counter_total_all$journal), 9)
  expect_equal(length(c), 1)
  expect_equal(length(d), 2)
  expect_equal(length(d$data$alm_twitterCount), 8)
  expect_equal(length(e$facet$alm_twitterCount), 2)
  expect_equal(NCOL(e$facet$alm_twitterCount$volume), 9)

  # classes
  expect_is(a, "sr_stats")
  expect_is(b, "list")
  expect_is(b$data, "data.frame")
  expect_is(b$facet$counter_total_all$journal, "data.frame")
  expect_is(c, "sr_stats")
  expect_equal(attr(c, "wt"), "json")
  expect_is(d, "list")
  expect_is(e, "list")

  # solr_stats
  expect_is(
    solr_stats(conn_plos,
      params = list(q='ecology',
        stats.field=c('counter_total_all','alm_twitterCount'),
                  stats.facet=c('journal','volume'))),
    "list"
  )
  expect_is(
    solr_stats(conn_plos,
      params = list(q='ecology',
        stats.field=c('counter_total_all','alm_twitterCount'),
                  stats.facet=c('journal','volume')), raw=TRUE),
    "sr_stats"
  )
})

test_that("solr_stats works using wt=xml", {
  skip_on_cran()

  aa <- conn_plos$stats(params = list(q='science', wt="xml", stats.field='counter_total_all'), raw=TRUE)
  bb <- conn_plos$stats(params = list(q='science', wt="xml", stats.field='counter_total_all'))
  cc <- conn_plos$stats(params = list(q='science', wt="xml", stats.field=c('counter_total_all','alm_twitterCount'),
                   stats.facet=c('journal','volume')))

  # correct dimenions
  expect_equal(length(aa), 1)
  expect_equal(length(bb), 2)
  expect_equal(NROW(bb$data), 1)
  expect_named(cc$facet[[1]], c("volume", "journal"))
  expect_equal(length(cc), 2)

  # classes
  expect_is(aa, "sr_stats")
  expect_is(bb, "list")
  expect_is(cc, "list")
  expect_is(bb$data, "data.frame")
  expect_is(cc$facet[[1]][[1]], "data.frame")
  expect_equal(attr(aa, "wt"), "xml")
})