Commits

Sam Toyer committed 659330f

Remove invindex, it is useless without *proper* search

Comments (0)

Files changed (2)

 /* client side logic for xonmaps */
 
+var word_re;
+
 function magnet_url(mapid) {
     return 'magnet:?xt=urn:sha1:' + mapdb[mapid]['sha1'] + '&as='
         + encodeURIComponent(direct_url(mapid)) + '&dn=' + encodeURIComponent(mapid)
     else header.removeClass("floatinghead");
 }
 
+Array.prototype.deduplicate = function() {
+    // in-place removal of duplicated elements
+    var new_arr = [];
+    while (this.length > 0) {
+        var c = this.pop();
+        if (this.indexOf(c) != -1) continue;
+        new_arr.push(c);
+    }
+    this.concat(new_arr); 
+}
+
+function Query(query) {
+    var words = query.match(word_re).map(function(e) {
+        return e.toLowerCase();
+    });
+    // don't double up query parameters!
+    words.deduplicate();
+    function in_gt(e) {
+        return config['gametypes'].indexOf(e) != -1;
+    }
+    this.gametypes = words.filter(in_gt);
+    this.words = words.filter(function(e) {
+        return !in_gt(e);
+    });
+    this.query = query;
+}
+
+function score_mapid(query_obj, mapid) {
+    /* Provides a search score for the given mapid and given query as part of
+     * the filtering process. FTS can be implemented more efficiently, but with
+     * a small number of maps our bottleneck is the DOM rather than outright
+     * search speed */
+    if (query_obj.gametypes.length > 0 && mapdb[mapid]['gametype'] == undefined) {
+        return 0;
+    }
+    // filter by gametype
+    for (gt in query_obj.gametypes) {
+        if (mapdb[mapid]['gametype'].indexOf(gt) == -1) return 0;
+    }
+    var score = 0;
+    for (word in query_obj.words) {
+        for (field in config['fts_fields']) {
+            var m1 = ftsindex[field[0]][word];
+            if (m1 == undefined) continue;
+            var m2 = m1[mapid];
+            if (m2 == undefined) continue;
+            // m2 is num occurrences and field[1] is the field weight
+            score += m2 * field[1];
+        }
+    }
+    return score;
+}
+
+function remove_gametype_tag(tag) {
+}
+
+function add_gametype_tag(tag) {
+    var e = $("#q");
+    var v = e.val();
+}
+
+function toggle_gametype_filter() {
+    /*var name = $(this).text();
+    var q = new Query($("#q").val());
+    if (q.gametype*/
+    alert("I haven't implemented that yet! Arrrrgh!");
+}
+
+function on_search() {
+    var q = new Query($(this).find("#q").val());
+    var e = $("#maps tr");
+    // XXX: inefficient
+    e.fadeIn();
+    e.filter(function() {
+        var mid = $(this).find(".rot").text();
+        return score_mapid(q, mid) > 0;
+    }).fadeOut();
+}
+
 $(document).ready(function() {
     $("#searchbox").toggle(300);
     $("#shadow").click(function() {$("#shadow, #downloadbox").fadeOut();});
     $("#maps tr").click(map_detail);
     $(document).scroll(snap_header);
+    word_re = new RegExp(config['word_regex'], 'g');
+    $(".gametypes .button").click(toggle_gametype_filter);
+    $("#qf").submit(on_search);
 });
         <div id="header">
             <h1>Xonotic Map Repository</h1>
             <div id="searchbox" class="invisible">
-                <input type="submit" id="go" value="search" />
-                <input type="text" id="q" placeholder='try "solarium" or "ctf"' />
+                <form action="#" method="get" id="qf">
+                    <input type="submit" id="go" value="search" />
+                    <input type="text" id="q" placeholder='try "solarium" or "ctf"' />
+                </form>
             </div>
         </div>
         <div id="downloadbox" class="invisible">
         <!-- to load FAST -->
         <script type="text/javascript" src="jquery-1.7.2.min.js"></script>
         <script type="text/javascript" src="mapdb.json"></script>
-        <script type="text/javascript" src="invindex.json"></script>
+        <!-- <script type="text/javascript" src="invindex.json"></script> -->
         <script type="text/javascript" src="ftsindex.json"></script>
         <script type="text/javascript" src="config.json"></script>
         <script type="text/javascript" src="xonmap.js"></script>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.