Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
lbell
Visitor

Noob needs help with search

Every time I try to search for something nothing happens.
No suggestions load and I don't get any results..
I can't seem to figure this out for the life of me..

I just used the sdk examples and tweaked them as needed
Here's the source code

Function SearchScreen()
InitTheme()

print "start"
'toggle the search suggestions vs. search history behavior
'this allow you to generate both versions of the example below
displayHistory = false
history = CreateObject("roArray", 1, true)
'prepopulate the search history with sample results
'history.Push("the old paths")
'history.Push("good news of the kingdom")

port = CreateObject("roMessagePort")
screen = CreateObject("roSearchScreen")
'commenting out SetBreadcrumbText() hides breadcrumb on screen
screen.SetBreadcrumbText("", "search")
screen.SetMessagePort(port)

if displayHistory = true
screen.SetSearchTermHeaderText("Recent Searches:")
screen.SetSearchButtonText("search")
screen.SetClearButtonText("clear history")
screen.SetClearButtonEnabled(true) 'defaults to true
screen.SetSearchTermHeaderText("Suggestions:")
else
screen.SetSearchTermHeaderText("Suggestions:")
screen.SetSearchButtonText("search")
screen.SetClearButtonEnabled(false)
endif

print "Doing show screen..."
screen.Show()
print "Waiting for a message from the screen..."

' search screen main event loop
done = false
while done = false
msg = wait(0, screen.GetMessagePort())
if type(msg) = "roSearchScreenEvent"
if msg.isScreenClosed()
print "screen closed"
done = true
screen.close()
else if msg.isCleared()
print "search terms cleared"
history.Clear()
else if msg.isPartialResult()
print "partial search: "; msg.GetMessage()
if not displayHistory
screen.SetSearchTerms(GenerateSearchSuggestions(msg.GetMessage()))
endif
else if msg.isFullResult()
print "full search: "; msg.GetMessage()
history.Push(msg.GetMessage())
if displayHistory
screen.AddSearchTerm(msg.GetMessage())
end if
Print "Delta"
searchResults(msg.GetMessage())

'uncomment to exit the screen after a full search result:
done = true
screen.close()
else
print "Unknown event: "; msg.GetType(); " msg: ";msg.GetMessage()
endif
endif
endwhile
print "Exiting..."
End Function


Function GenerateSearchSuggestions(partSearchText As String) As Object

suggestions = CreateObject("roArray", 1, true)

url = "http://www.map2life.com/roku/php/search.php?"
partsearch = url + partSearchText

Print"Searchconn()"
alpha = searchconn(partsearch)

If aplha <> "Can't parse feed" then
Print "alpha push"

for each e in alpha
suggestions.push(e.Title)
end for

Print "Alpha push completed"
else
Print "Error in search suggestion parse"
end if

return suggestions

End Function



Function searchResults(searchtext As String) As Void

url = "http://www.map2life.com/roku/php/search.php?"

search = url + searchtext

results = searchconn(search)

If results = "Can't parse feed" then
text = "I'm sorry, we Couldn't find any results for your request. Try rewording your request."
title = "Search Error"
ShowDialog1Button(title, text, "Done")
else
Print "Bravo 1"
screen = preShowDetailScreen("", "Search Results")
index = 0
showDetailScreen(screen, results, index)
end if

End Function



Function searchconn(searchUrl As String) As Dynamic


print searchUrl
http = NewHttp(searchUrl)

'm.Timer.Mark()
rsp = http.GetToStringWithRetry()
'print "Request Time: " + itostr(m.Timer.TotalMilliseconds())

feed = newShowFeed()
xml=CreateObject("roXMLElement")
if not xml.Parse(rsp) then
print "Can't parse feed"
Error = "Can't parse feed"
return Error
endif

if xml.GetName() <> "feed" then
print "no feed tag found"
Error = "Can't parse feed"
return Error
endif

if islist(xml.GetBody()) = false then
print "no feed body found"
Error = "Can't parse feed"
return Error
endif

'm.Timer.Mark()
results = searchfeedparse(xml, feed)
'print "Search Feed Parse Took : " + itostr(m.Timer.TotalMilliseconds())
print "Search feed parse success"

return results

End Function


Function searchfeedparse(xml As Object, feed As Object) As Object

showCount = 0
showList = xml.GetChildElements()

for each curShow in showList

'for now, don't process meta info about the feed size
if curShow.GetName() = "resultLength" or curShow.GetName() = "endIndex" then
goto skipitem
endif

item = init_show_feed_item()

'fetch all values from the xml for the current show
item.hdImg = validstr(curShow@hdImg)
item.sdImg = validstr(curShow@sdImg)
item.ContentId = validstr(curShow.contentId.GetText())
item.Title = validstr(curShow.title.GetText())
item.Description = validstr(curShow.description.GetText())
item.ContentType = validstr(curShow.contentType.GetText())
item.ContentQuality = validstr(curShow.contentQuality.GetText())
item.Synopsis = validstr(curShow.synopsis.GetText())
item.Genre = validstr(curShow.genres.GetText())
item.Runtime = validstr(curShow.runtime.GetText())
item.ImageCount = strtoi(validstr(curShow.ImageCount.GetText()))
item.Url = validstr(curShow.Url.GetText())
item.HDBifUrl = validstr(curShow.hdBifUrl.GetText())
item.SDBifUrl = validstr(curShow.sdBifUrl.GetText())
item.StreamFormat = validstr(curShow.streamFormat.GetText())
item.StreamBitrates.Push(strtoi(validstr(curShow.streamBitrate.GetText())))
item.StreamQualities.Push(validstr(curShow.streamQuality.GetText()))
item.StreamUrls.Push(validstr(curShow.streamUrl.GetText()))

if item.StreamFormat = "" then 'set default streamFormat to mp4 if doesn't exist in xml
item.StreamFormat = "mp4"
endif

'map xml attributes into screen specific variables
item.ShortDescriptionLine1 = item.Title
item.ShortDescriptionLine2 = item.Description
item.HDPosterUrl = item.hdImg
item.SDPosterUrl = item.sdImg

item.Length = strtoi(item.Runtime)
item.Categories = CreateObject("roArray", 5, true)
item.Categories.Push(item.Genre)
item.Actors = CreateObject("roArray", 5, true)
item.Actors.Push(item.Genre)
item.Description = item.Synopsis

'Set Default screen values for items not in feed
item.HDBranded = false
item.IsHD = false
item.StarRating = "0"
item.ContentType = "episode"

showCount = showCount + 1
feed.Push(item)

skipitem:

next

return feed

End Function



0 Kudos
2 REPLIES 2
TheEndless
Channel Surfer

Re: Noob needs help with search

Have you actually debugged this in the debug console? There are two issues that I see, both with the "alpha" check in GenerateSearchSuggestions.


  1. You've misspelled "alpha" as "aplha" which will crash with a "Use ofun initialized variable." error.

  2. searchconn() returns either an array or a string, but you're checking to see if the value of alpha is (not) equal to a specific string ("Can't parse feed"). If searchconn() successfully returns a search results array, then this check will crash with a "Type mismatch." error.

If you change that line to the following, it should work:
if islist(alpha) then

You have a similar issue in your searchResults() function. You also have a typo in the StreamUrl node of your search XML. And, you really should URL encode the search text before appending it to the search URL.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
lbell
Visitor

Re: Noob needs help with search

No, I didn't debug..My friend loads them for me cause I don't have a Roku.
I didn't even think of a type mismatch error..It does make way more sense to test it with islist() though.
Thank you! I t works great now!
0 Kudos