1setGeneric("readSolrDoc",
2           function(doc, ...)
3             standardGeneric("readSolrDoc"))
4
5setMethod("readSolrDoc", "character",
6           function(doc, ...)
7              readSolrDoc(xmlParse(doc), ...))
8
9setMethod("readSolrDoc", "AsIs",
10           function(doc, ...)
11              readSolrDoc(xmlParse(doc), ...))
12
13setMethod("readSolrDoc", "XMLInternalDocument",
14           function(doc, ...)
15              readSolrDoc(xmlRoot(doc), ...))
16
17
18setMethod("readSolrDoc", "XMLInternalNode",
19           function(doc, ...) {
20             kids = xmlChildren(doc)
21             kids = kids[!sapply(kids, inherits, "XMLInternalCommentNode")]
22             if(length(kids) == 0)
23                return(list())
24
25             keys = sapply(kids, xmlGetAttr, "name")
26             structure(lapply(kids, readSolrNodeValue),
27                       names = keys)
28           })
29
30
31readSolrNodeValue =
32function(node)
33{
34  id = xmlName(node)
35  switch(id, int = if(abs(tmp <- as.numeric(xmlValue(node))) > .Machine$integer.max) tmp else as.integer(xmlValue(node)),
36             long = as.numeric(xmlValue(node)),
37             str = xmlValue(node),
38             lst = readSolrDoc(node),
39             bool = as.logical(xmlValue(node)),
40             date = as.POSIXct(strptime(xmlValue(node), "%Y-%m-%dT%H:%M:%SZ")),
41           )
42}
43
44
45
46
47
48