[Debtags-commits] [svn] r1937 - in web/trunk: . js
Enrico Zini
enrico at costa.debian.org
Fri Sep 22 22:27:47 UTC 2006
Author: enrico
Date: Fri Sep 22 22:27:46 2006
New Revision: 1937
Added:
web/trunk/ssearch.html
Modified:
web/trunk/js/debtags.js
web/trunk/js/test.html
Log:
Added smart search
Modified: web/trunk/js/debtags.js
==============================================================================
--- web/trunk/js/debtags.js (original)
+++ web/trunk/js/debtags.js Fri Sep 22 22:27:46 2006
@@ -86,6 +86,59 @@
);
}
+function fireSTAGSQuery(str, progressFunc, finalFunc, async)
+{
+ // Build the new search base
+ var keys = str.split(" ");
+ for (i in keys)
+ keys[i] = escape(keys[i]);
+
+ runRequest(QUERY_BASE + "/stags/"+keys.join('/'),
+ function(lines) {
+ var ts = new Array();
+ for (i in lines)
+ {
+ var fields = lines[i].split(" ");
+ ts.push(fields);
+ }
+ progressFunc(ts);
+ },
+ function(lines) {
+ var ts = new Array();
+ for (i in lines)
+ {
+ var fields = lines[i].split(" ");
+ ts.push(fields);
+ }
+ finalFunc(ts);
+ },
+ async
+ );
+}
+
+function firePKGSQuery(ts, progressFunc, finalFunc, async)
+{
+ var tags = new Array();
+ ts.each(function(i){tags.push(escape(i))});
+ runRequest(QUERY_BASE + "/pkgs/"+tags.join('/'),
+ function(lines) {
+ var coll = new Collection();
+ var pkgs = new Packages();
+ coll.decode(lines);
+ pkgs.decode(lines);
+ progressFunc(coll, pkgs);
+ },
+ function(lines) {
+ var coll = new Collection();
+ var pkgs = new Packages();
+ coll.decode(lines);
+ pkgs.decode(lines);
+ finalFunc(coll, pkgs);
+ },
+ async
+ );
+}
+
//
// Debtags infrastructure
//
@@ -132,7 +185,7 @@
},
addFirstTags: function(tags) {
var total = 0;
- function score(x) { return float((x-15)*(x-15))/x; }
+ function score(x) { return ((x-15)*(x-15))/x; }
for (i in tags) {
var tag = tags[i][0];
@@ -156,7 +209,19 @@
merge: function(tset) {
var tmp=this;
tset.each(function(i){tmp.add(i)});
- }
+ },
+ contains: function(tset) {
+ for (var i in tset._items)
+ if (!this.has(i))
+ return false;
+ return true;
+ },
+ intersects: function(tset) {
+ for (var i in tset._items)
+ if (this.has(i))
+ return true;
+ return false;
+ },
};
Collection = function() {
Modified: web/trunk/js/test.html
==============================================================================
--- web/trunk/js/test.html (original)
+++ web/trunk/js/test.html Fri Sep 22 22:27:46 2006
@@ -129,6 +129,14 @@
ensure("debtags should have use::searching tag", ts.has("use::searching"));
ensure("debtags should have works-with::software:package tag", ts.has("works-with::software:package"));
//ts.each(function(a){document.write(a);});
+
+var progressCount = 0;
+var t = null;
+fireSTAGSQuery("image editor", function(tags){++progressCount;}, function(tags){t=tags;}, false);
+ ensure_equals("sync query has no partial events", progressCount, 0);
+ ensure("should have a result", t != null);
+ ensure("should have more than 10 tags inside", t.length > 10);
+
/*
var a = {};
a["antani"] = "blinda";
More information about the Debtags-commits
mailing list