Collaborama About Help Contact Anonymous [login] Source: site.view [edit] Function name: searchapps Arguments: query,device Description: Searches for apps using a query, limited to a device type. Page type: webl Render function: mapp.resultsRender Module: mapp Page source: var res = []; var clean = fun(str) str= Wub_ReplaceAll(str, "+", ""); str= Wub_ReplaceAll(str, "-", ""); str= Wub_ReplaceAll(str, "&", ""); str= Wub_ReplaceAll(str, "|", ""); str= Wub_ReplaceAll(str, "(", ""); str= Wub_ReplaceAll(str, ")", ""); str= Wub_ReplaceAll(str, "{", ""); str= Wub_ReplaceAll(str, "}", ""); str= Wub_ReplaceAll(str, "^", ""); str= Wub_ReplaceAll(str, "%", ""); str= Wub_ReplaceAll(str, "\"", ""); str= Wub_ReplaceAll(str, "'", ""); str= Wub_ReplaceAll(str, "*", ""); str= Wub_ReplaceAll(str, "~", ""); str= Wub_ReplaceAll(str, ":", ""); str= Wub_ReplaceAll(str, "\\", ""); str= Wub_ReplaceAll(str, "?", ""); str= Wub_ReplaceAll(str, "!", ""); str= Wub_ReplaceAll(str, ".", ""); str= Wub_ReplaceAll(str, "", ""); return str end; var rewriteQuery = fun(q, dev) var w = [. "ipad" = [" for ipad ", " hd ", " ipad "], "ipod" = [" for ipod", " ipod "], "mac" = [" for mac", " mac "], "iphone" = [" for iphone", " iphone "] , "-" = [" free ", " cheap ", " app ", " apps ", " cool ", " great ", " good ", " top ", " new ", " rad ", " application ", " applications " ] .]; var q2 = " " + Str_ToLowerCase(q) + " "; var res = []; every d in w do every srch in w[d] do res = res + [ srch ]; var p = Str_IndexOf(srch, q2); if (p >= 0) then q2 = Select(q2, 0, p) + Select(q2, p+Size(srch) - 1, Size(q2) ); if (d != "-") then dev = d end end; end; end; q2 = Str_Trim(q2); if q2 == "" then q2 = "the" end; return [. q = clean(q2), origq = q, device=dev .] end; var rewrite = rewriteQuery(query, device); var reader2 = Wub_ReadLuceneIndex("apps"); var whichDevices = ""; if rewrite.device != "all" then whichDevices = `AND device:` + rewrite.device; end; var luceneq = `(genres: ` + rewrite.q + `) ` + whichDevices; // var luceneq = `(title:"`+ rewrite.q + `"^2 OR query:` + rewrite.q +` OR genres:"` + rewrite.q + `"^3) ` + whichDevices; var docs2 = Wub_LuceneSearch(reader2, "genres", luceneq, 20, "standard"); Wub_CloseLuceneIndex(reader2); var i = 0; var sz = (docs2.size() ? 0); while (i < sz) do var d = [. .]; var doc = docs2.get(i).getDoc(); d["id"] := doc.getField("id").stringValue(); d["title"] := doc.getField("title").stringValue(); d["artist"] := doc.getField("artist").stringValue(); d["seller"] := doc.getField("seller").stringValue(); d["description"] := doc.getField("description").stringValue(); d["art"] := doc.getField("art").stringValue(); d["artsmall"] := doc.getField("artsmall").stringValue(); d["view"] := doc.getField("view").stringValue(); d["release"] := doc.getField("release").stringValue(); d["version"] := doc.getField("version").stringValue(); d["devices"] := doc.getField("device").stringValue(); d["rank"] := doc.getField("rank").stringValue(); d["boost"] := doc.getField("boost").stringValue(); d["genres"] := doc.getField("genres").stringValue(); res = res + [d]; i = i + 1 end; [. query = rewrite.origq, newq = rewrite.q, device=device, apps = res .];