-------------------------------- function isWhitespace (ch) { if (ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' || ch == '\f' || ch == '\v' || ch == '\b') return true; return false; } --------------------------------- function isDelimiter (ch) { if (ch == ',' || ch == '?' || ch == '-' || ch == '.' || ch == '\\' || ch == '/') return true; return false; } ----------------------------------- function KeywordList () { this.count = 0; this.word = new Object (); this.add = AddKeyword; return this; } function AddKeyword (word) { for (var i = 0; i < this.count; i++) if (this.word[i] == word) return; this.word[this.count++] = word; } ------------------------------------- function parseKeywords (str) { var list = new KeywordList (); var inword = false; var word = ""; var len = str.length; for (var i = 0; i < len; i++) { var ch = str.charAt(i); if (isWhitespace(ch) || isDelimiter(ch)) { if (inword) { list.add(word); word = ""; inword = false; } } else { word += ch; inword = true; } if (i + 1 == len && inword) list.add(word); } return list; } ------------------------------------- function IndexItemList () { this.count = 0; this.item = new Object(); this.add = AddIndexItem; return this; } function AddIndexItem (object) { this.item[this.count++] = object; } function Index () { this.count = 0; this.item = new Object(); this.add = AddToIndex; return this; } function AddToIndex (object, keywords) { for (var i = 0; i < keywords.count; i++) { var kw = keywords.word[i]; var ilist = this.item[kw]; if (ilist == null) { ilist = new IndexItemList(); this.item[kw] = ilist; } ilist.add(object); } } ----------------------------------------- // ITT A KONYV SZERZOJE,CIME,TARGYA,KODJA ES ARA!! --> function Book (author, title, subject, code, price) { this.author = author; this.title = title; this.subject = subject; this.code = code; this.price = price; return this; } function Catalog () { this.count = 0; this.book = new Object; this.author = new Index(); this.title = new Index(); this.subject = new Index(); this.add = AddToCatalog; return this; } function AddToCatalog (book) { this.book[this.count++] = book; this.author.add(book,parseKeywords(book.author)); this.title.add(book,parseKeywords(book.title)); this.subject.add(book,parseKeywords(book.subject)); } ---------------------------------------- // A KATALOGUS ES 7 KONYV ADATAI--> var cat = new Catalog(); cat.add (new Book ("Kingsolver, Barbara", "Animal Dreams", "fiction animals dreams environment Native-American love", "ISBN 0-06-092114-5", 13.00)); cat.add (new Book ("Calasso, Roberto", "The Marriage of Cadmus and Harmony", "fiction Greek myth mythology Zeus Athens", "ISBN 0-679-73348-5", 13.00)); cat.add (new Book ("Le Carre, John", "The Night Manager", "fiction suspense spy arms drugs", "ISBN 0-345-38576-4", 6.99)); cat.add (new Book ("Rice, Anne", "Interview with the Vampire", "fiction vampire New Orleans gothic horror", "ISBN 0-345-33766-2", 4.95)); cat.add (new Book ("Garcia Marquez, Gabriel", "One Hundred Years of Solitude", "fiction South America magic dreams war love", "ISBN 0-06-091965-5", 13.00)); cat.add (new Book ("Barkakati, Naba", "Object-Oriented Programming in C++", "nonfiction computer language programming object C", "ISBN 0-672-22800-9", 29.95)); cat.add (new Book ("Petzold, Charles", "Programming Windows", "nonfiction computer programming C windows", "ISBN 1-55615-264-7", 29.95)); ------------------------------------------- // A KERESES EREDMENYE ES OBJEKTUMA!! --> function Result (object, score) { this.object = object; this.score = score; return this; } function ResultList () { this.count = 0; this.item = new Object(); this.add = AddResult; this.sort = SortResults; return this; } function AddResult (object) { for (var i = 0; i < this.count; i++) if (this.item[i].object == object) { this.item[i].score++; return; } this.item[this.count++] = new Result (object,1); } function SortResults () { pm_array_qsort (this.item,0,this.count - 1,CompareResults); } function CompareResults (a,b) { return (a.score == b.score) ? 0 : (a.score < b.score) ? 1 : -1; } -------------------------------------------- function Index () { this.count = 0; this.item = new Object(); this.add = AddToIndex; this.find = SearchIndex; return this; } function SearchIndex (keywords) { var rlist = new ResultList(); for (var i = 0; i < keywords.count; i++) { var kw = keywords.word[i]; var ilist = this.item[kw]; if (ilist != null) for (var j = 0; j < ilist.count; j++) rlist.add(ilist.item[j]); } rlist.sort(); return rlist; } ---------------------------------------- // EZ AZ UTOLSO: A KONYVUZLET INTERFACE-E!! --> var controlFrame = '' + '
' + '' + '' + '' + '' + '' + '
Search by: Keywords:
' + '
' + ''; var results = null; function doSearch () { var index = self.head.document.cont.stype.selectedIndex; var keywords = parseKeywords (self.head.document.cont.keywords.value); if (index == 0) results = cat.title.find (keywords); else if (index == 1) results = cat.author.find (keywords); else results = cat.subject.find (keywords); self.body.location = "javascript:parent.showList()"; } function showBook (item) { var book = results.item[item].object; var detail = book.author + '
' + book.title + '
' + book.subject + '
' + book.code + '
$' + book.price + '
' + '

Return to list

'; return '
' + detail + '
'; } function showList () { var list = ""; for (var i = 0; i < results.count; i++) list += '
' + '(' + results.item[i].score + ')  ' + results.item[i].object.author + ':  ' + results.item[i].object.title + '
'; if (list.length == 0) list = '

Sorry, no matches found

'; return '
' + list + '
'; } ---------------------------------------------------------------351CF202186514AC--