|
|
|
Text Search Engine
Added on 9/27/1999
|
This behavior sets up a text search. Use field members for the search field, result box, name of the article, current result number, and total results. For the buttons use any other type of cast member. On the searchButton declare the list of the cast libraries to search as a text string separated by commas and no extra spaces. For source file and more detailed explination, check out the article
--Use field members for the search field, result box, name of the article, current result number, and total results. For the buttons use any other type of cast member.
--On the searchButton declare the list of the cast libraries to search as a text string separated by commas and no extra spaces.
--Copyright 1999 Chuck Neal
--chuck@mediamacros.com
--If you find this code helpful, send me an e-mail and let me know. :-)
property whichItem, spriteNum, theCastList
global searchResults, itemsList
on getPropertyDescriptionList me
p_list = [:]
if the currentSpriteNum > 0 then
if sprite(the currentSpriteNum).member.type <> #field then
--is not one of the fields/text members use as one of the buttons
p_list.addProp(#thecastlist, [#format : #string, #default : "text", #comment : "Which castlib(separate with commas and no spaces):"])
p_list.addProp(#whichItem, [#format : #symbol, #default : #search, #comment : "Which button:", #range : [#SearchButton, #SearchAgainButton, #searchPreviousButton]])
else
p_list.addProp(#whichItem, [#format : #symbol, #default : #SearchField, #comment : "Which field:", #range : [#SearchField, #SearchResults, #Results1, #Results2, #ArticleName]])
end if
end if
return p_list
end
on beginSprite me
if itemsList = void then itemsList = [#currentSearch : 0]
--establish where everything is
itemsList[whichItem] = spriteNum
--clear the text
clear()
end
on clear me
if [#Results1 , #results2, #searchResults, #ArticleName, #searchField].getOne(whichItem) <> 0 then
sprite(spriteNum).member.text = ""
end if
end
on mouseDown me
case whichItem of
#searchButton :
itemsList[#currentSearch] = 1
searchResults = searchText(sprite(itemsList[#searchButton]).theCastList, sprite(itemsList[#searchField]).member.text)
if searchResults = [] then
--no results
alert "No matching results found"
sendAllSprites(#clear)
else
sendAllSprites(#nextSearch)
end if
#searchAgainButton :
if itemsList[#currentSearch] < searchResults.count then
itemsList[#currentSearch] = itemsList[#currentSearch] + 1
sendAllSprites(#nextSearch)
else if searchResults.count > 1 then
alert "Last found result. Beginning again from first result."
itemsList[#currentSearch] = 1
sendAllSprites(#nextSearch)
else
alert "There was only one match to your query"
end if
#searchPreviousButton :
if itemsList[#currentSearch] > 1 then
itemsList[#currentSearch] = itemsList[#currentSearch] - 1
sendAllSprites(#nextSearch)
else if searchResults.count > 1 then
alert "This is the first result. Returning to the end of the list."
itemsList[#currentSearch] = searchResults.count
sendAllSprites(#nextSearch)
else
alert "There was only one match to your query"
end if
end case
end
on nextSearch me
case whichItem of
#Results1 :
sprite(spriteNum).member.text = string(itemsList[#currentSearch])
#results2 :
sprite(spriteNum).member.text = string(searchResults.count)
#searchResults :
--see if it is the same member as the last search
if sprite(spriteNum).member.text <> searchResults[itemsList[#currentSearch]][1].text then
sprite(spriteNum).member.text = searchResults[itemsList[#currentSearch]][1].text
end if
sprite(spriteNum).member.scrolltop = (charPosToLoc(sprite(spriteNum).member, searchResults[itemsList[#currentSearch]][2])).locV - (sprite(spriteNum).member.lineheight)
hilite char searchResults[itemsList[#currentSearch]][2] to searchResults[itemsList[#currentSearch]][3] of member the member of sprite spriteNum
#ArticleName :
sprite(spriteNum).member.text = searchResults[itemsList[#currentSearch]][1].name
end case
end
on searchText castlist, textString
resultList = []
the itemDelimiter = ","
repeat with x = 1 to castlist.item.count
repeat with y = 1 to (the number of members of castlib x)
if [#text, #field].getOne(member(y, castlist.item[x]).type) <> 0 then
if member(y, castlist.item[x]).text contains textString then
--string is in the text search for all instances
offsetItem = 0
tempText = member(y, castlist.item[x]).text
repeat while tempText contains textString
theOffset = offset(textString, tempText)
offSetEnd = theOffset + (textString.char.count - 1)
resultList.add([member(y, castlist.item[x]), theOffset + offsetItem, offsetEnd + offsetItem])
offsetItem = offsetItem + offsetEnd
tempText = tempText.char[(offsetEnd + 1)..(tempText.char.count)]
end repeat
end if
end if
end repeat
end repeat
return resultList
end
on getBehaviorDescription me
describe = "This behavior sets up a text search. Use field members for the search field, result box, name of the article, current result number, and total results."
describe = describe & return & "For the buttons use any other type of cast member. On the searchButton declare the list of the cast libraries to search as a text string separated by commas and no extra spaces."
return describe
end
|
|