Root.searchSites (query, sid)
Search one or more (public) sites. Returns an array containing site-aliases and story ids of matching items.

  • Parameter query:
    The unprocessed query string
  • Parameter sid:
    ID of site in which to search, null searches all
  • Returns
    The result array
Sourcecode in Root/objectFunctions.js:
1:   function searchSites (query, sid) {
2:      // result array
3:      var result = new Array();
4:   
5:      // break up search string
6:      var unquote = new RegExp("\\\\", "g");
7:      query = query.replace(unquote, "\\\\");
8:      unquote = new RegExp("\'", "g");
9:      query = query.replace(unquote, "\'\'");
10:     var qarr = query.split(" ");
11:  
12:     // construct query
13:     var where = "select AV_TEXT.TEXT_ID, AV_SITE.SITE_ALIAS from AV_TEXT, AV_SITE where "+
14:                 "AV_TEXT.TEXT_F_SITE = AV_SITE.SITE_ID and "+
15:                 "AV_TEXT.TEXT_ISONLINE > 0 and ";
16:     for (var i in qarr) {
17:        where += "(AV_TEXT.TEXT_RAWCONTENT like '%"+qarr[i].toLowerCase()+"%') "
18:        if (i < qarr.length-1)
19:           where += "and ";
20:     }
21:     // search only in the specified site
22:     if (sid)
23:        where += "and AV_SITE.SITE_ID = "+sid+" ";
24:     else
25:        where += "and AV_SITE.SITE_ISONLINE > 0 ";
26:     where += "order by AV_TEXT.TEXT_CREATETIME desc";
27:  
28:     var dbcon = getDBConnection ("antville");
29:     var dbres = dbcon.executeRetrieval(where);
30:     if (dbres) {
31:        while (dbres.next()) {
32:           var item = new Object();
33:           item.sid = dbres.getColumnItem (1).toString();
34:           item.sitealias = dbres.getColumnItem (2);
35:           result[result.length] = item;
36:        }
37:     }
38:     dbres.release();
39:     return result;
40:  }