Forum Discussion

SkipFire's avatar
SkipFire
Visitor
14 years ago

Store Search History

I am looking for suggestions on how best to store the history for the search screen. It is populated from an roArray, but when I try to write the roArray to the registry it complains of a type mismatch. I would like to hear how others have done this. I would prefer to keep the search term on the Roku rather than sending it to the server.

I appreciate hearing how you have done this.

Thanks.

6 Replies

    • SoutheastTxman's avatar
      SoutheastTxman
      Newbie
      Is there a simple way to search history by date or otherwise? We installed YouTube on the roku and we want to know what has been watched. I am not a programmer. Thank you in advance
  • I looked at that, but I don't want to use the global search history in my app. I get annoyed enough by the apps that already use it.
  • "SkipFire" wrote:
    when I try to write the roArray to the registry it complains of a type mismatch. I would like to hear how others have done this. I would prefer to keep the search term on the Roku rather than sending it to the server.


    You can only write strings to the registry. One solution would be to use roXMLElement to build a chunk of XML representing the contents of your search history array and store that in the registry.
  • Here is some code that I have used, while out of context, it might provide some clues to help you. At the bottom are some of my registry management functions.

    *********************************************************************
    Write the current search term to the registry: (note, this is an excerpt and is based on previous search terms having already been loaded into histlist from the registry. It checks if the search term is already in the registry and if not then it adds it to the list and removes the oldest term from the list)

     
    'code excerpt from a search screen
    'm.tquerystring contains is the current search term.
    'histlist contains list of search terms loaded from the registry
    histlist=m.historylist 'this line should go at the very top of the search function

    flag=0

    for i=0 to histlist.count()-1
    if m.tquerystring=histlist[i]
    flag=1
    end if
    next i
    if flag <> 1 then
    histlist.unshift(m.tquerystring)
    if histlist.count() > 9
    histlist.pop()
    end if
    end if
    searchscr.setsearchterms(histlist)
    m.historylist=histlist
    writereg("history","searchhist",arraytostring(histlist))



    function AddHistory(id,histlist) as object
    flag=0
    for i=0 to histlist.count()-1
    if id=histlist[i]
    flag=1
    end if
    next i

    if flag <> 1 then
    histlist.unshift(id)
    if histlist.count() > 10
    histlist.pop()
    end if
    end if
    m.mixhist=histlist
    writereg("history","mixhist",arraytostring(histlist))
    return m.mixhist
    end function


    function arraytostring(array as object) as string
    str=""
    for each element in array
    if element <> invalid
    str=element+","+str
    end if
    next
    return left(str,len(str)-1)
    end function


    function loadsearchHistory() 
    if not checkreg("history","searchhist") then
    ?"no search history in the registry"
    createregsection("history","searchhist", "")
    else
    ?"found search history, loading"
    histemp=box(readreg("history","searchhist").tokenize(","))
    i=histemp.count()-1
    j=0
    while true
    if i=-1 or j > histemp.count() -1
    exit while
    end if
    m.historylist[j]=histemp[i]
    i=i-1
    j=j+1
    end while
    end if
    end function


    function createregsection(secname as string,keyname as string, keyvalue as string)
    registry=createobject("roregistry")
    section=createobject("roregistrysection",secname)
    section.write(keyname,keyvalue)
    end function

    function checkreg(secname as string,keyname as string) as boolean
    registry=createobject("roregistry")
    section=createobject("roregistrysection",secname)
    return section.exists(keyname)
    end function

    function readreg(secname as string, keyname as string) as string
    registry=createobject("roregistry")
    section=createobject("roregistrysection",secname)
    return section.read(keyname)
    end function

    function writereg(secname as string, keyname as string, keyvalue as string) as boolean
    registry=createobject("roregistry")
    section=createobject("roregistrysection",secname)
    section.write(keyname,keyvalue)
    end function

    function deletekey(secname as string,keyname as string) as boolean
    registry=createobject("roregistry")
    section=createobject("roregistrysection",secname)
    return section.delete(keyname)
    end function

    function deleteSection(secname as string) as boolean
    registry=createobject("roregistry")
    return registry.delete(secname)
    end function

    function regflush()
    registry=createobject("roregistry")
    registry.flush()
    end function
  • RokuJoel, I didn't know about tokenize but that makes it quite easy thanks.

    RokuChris, thanks for the XML suggestion.