def search(cond, depth)
Utility::check_types({ cond=>Condition, depth=>Integer }) if $DEBUG
@status = -1
return nil unless @url
turl = @url + "/search"
reqheads = [ "Content-Type: application/x-www-form-urlencoded" ]
reqheads.push("Authorization: Basic " + Utility::base_encode(@auth)) if @auth
reqbody = Utility::cond_to_query(cond, depth, @wwidth, @hwidth, @awidth)
resbody = StringIO::new
rv = Utility::shuttle_url(turl, @pxhost, @pxport, @timeout, reqheads, reqbody, nil, resbody)
@status = rv
return nil if rv != 200
lines = resbody.string.split(/\n/, -1)
return nil if lines.length < 1
docs = []
hints = {}
nres = NodeResult::new(docs, hints)
border = lines[0]
isend = false
lnum = 1
while lnum < lines.length
line = lines[lnum]
lnum += 1
if line.length >= border.length && line.index(border) == 0
isend = true if line[border.length...line.length] == ":END"
break
end
lidx = line.index("\t")
if lidx
key = line[0...lidx]
value = line[(lidx+1)...line.length]
hints[key] = value
end
end
snum = lnum
while !isend && lnum < lines.length
line = lines[lnum]
lnum += 1
if line.length >= border.length && line.index(border) == 0
if lnum > snum
rdattrs = {}
sb = StringIO::new
rdvector = ""
rlnum = snum
while rlnum < lnum - 1
rdline = lines[rlnum].strip
rlnum += 1
break if rdline.length < 1
if rdline =~ /^%/
lidx = rdline.index("\t")
rdvector = rdline[(lidx+1)...rdline.length] if rdline =~ /%VECTOR/ && lidx
else
lidx = rdline.index("=")
if lidx
key = rdline[0...lidx]
value = rdline[(lidx+1)...rdline.length]
rdattrs[key] = value
end
end
end
while rlnum < lnum - 1
rdline = lines[rlnum]
rlnum += 1
sb.printf("%s\n", rdline)
end
rduri = rdattrs["@uri"]
rdsnippet = sb.string
if rduri
rdoc = ResultDocument::new(rduri, rdattrs, rdsnippet, rdvector)
docs.push(rdoc)
end
end
snum = lnum
isend = true if line[border.length...line.length] == ":END"
end
end
return nil if !isend
return nres
end