pike.git / lib / modules / Search.pmod / Database.pmod / MySQL.pike

version» Context lines:

pike.git/lib/modules/Search.pmod/Database.pmod/MySQL.pike:17:    Sql.Sql get_db()    {    return Sql.Sql(host);    }    mapping options;    string mergefile_path;    int mergefile_counter = 0;    int init_done = 0;   };    - protected void create(string db_url, void|mapping _options) + protected void create(string db_url, mapping options = ([]))   {    host = db_url;    get_db(); -  options = _options || ([]); +     mergefile_path = options->mergefiles;       if(!mergefile_path)    mergefile_path = "/tmp/";       if(options->mergefiles)    foreach(get_mergefiles(), string fn)    rm(fn);   }   
pike.git/lib/modules/Search.pmod/Database.pmod/MySQL.pike:246:   mapping|zero get_uri_and_language(int|array(int) doc_id)   {    Sql.Sql db = get_db();    if(arrayp(doc_id))    {    array a=db->query("select document.id,document.language, uri.uri from document, uri "    "where uri.id=document.uri_id and document.id IN ("+    ((array(string))doc_id)*","+")");    return mkmapping( (array(int))a->id, a );    } -  else -  { +     array a=db->query("select document.language,uri.uri from document,uri "    "where uri.id=document.uri_id and document.id=%d",doc_id);    if(!sizeof(a))    return 0;       return (["uri":1,"language":1]) & a[0];   } - } +       void remove_uri(string|Standards.URI uri)   {    Sql.Sql db = get_db();    db->query("delete from uri where uri_md5=%s", to_md5((string)uri));   }      void remove_uri_prefix(string|Standards.URI uri)   {    Sql.Sql db = get_db();
pike.git/lib/modules/Search.pmod/Database.pmod/MySQL.pike:345:   {    // FIXME: Make something better       Sql.Sql db = get_db();    array a = db->query("select max(doc_id) as m, count(*) as c from deleted_document");    int max_id = (int)a[0]->m;    int count = (int)a[0]->c;       if(max_id==deleted_max && count == deleted_count)    return deleted_documents; -  else -  { +     array ids = (array(int))db->query("select doc_id from deleted_document "    "order by doc_id")->doc_id;    deleted_count = count;    deleted_max = max_id;    return deleted_documents = Search.ResultSet(ids);   } - } +       Search.ResultSet get_all_documents()   {    Sql.Sql db = get_db();    array ids =    (array(int)) db->query("SELECT id FROM document ORDER BY id")->id;    return Search.ResultSet(ids);   }      
pike.git/lib/modules/Search.pmod/Database.pmod/MySQL.pike:514:    if (sizeof(non_glob_words)) {    string first_word_sql = string_to_utf8(non_glob_words[0]);    return map(db->query("SELECT DISTINCT word, "    " LOCATE(%s, word) AS score "    " FROM word_hit "    " WHERE word LIKE %s "    " ORDER BY score ASC, word ASC "    " LIMIT %d",    first_word_sql, g_sql, max_hits)->word,    utf8_to_string); -  } else { +  }    return map(db->query("SELECT DISTINCT word "    " FROM word_hit "    " WHERE word LIKE %s "    " ORDER BY word ASC "    " LIMIT %d",    g_sql, max_hits)->word,    utf8_to_string);    } -  } else { +     return map(db->query("SELECT DISTINCT word "    " FROM word_hit "    " WHERE word LIKE %s",    g_sql)->word,    utf8_to_string);   } - } +          int get_padded_blob_length(int used_len)   {    // Suggest a padded length based on current length. We'll use this    // strategy:    //    // - no blobs smaller than 64 bytes    // - blobs grow 25% rounded up to nearest 64 bytes    int new_len = (((used_len >> 2) + used_len) | 63) + 1;
pike.git/lib/modules/Search.pmod/Database.pmod/MySQL.pike:630:    doc_id = get_document_id((string)uri, language, 1);    Sql.Sql db = get_db();    db->query("delete from metadata where doc_id = %d", doc_id);   }      protected string make_fields_sql(void|array(string) wanted_fields)   {    Sql.Sql db = get_db();    if(wanted_fields && sizeof(wanted_fields))    return " and name IN ('"+map(wanted_fields,db->quote)*"','"+"')"; -  else +     return "";   }      mapping(string:string) get_metadata(int|Standards.URI|string uri,    void|string language,    void|array(string) wanted_fields)   {    int doc_id;    if(intp(uri))    doc_id=uri;
pike.git/lib/modules/Search.pmod/Database.pmod/MySQL.pike:752:   {    _WhiteFish.DateSet dateset_cache;    int dateset_cache_max_doc_id = -1;       int get_max_doc_id()    {    Sql.Sql db = get_db();    array a = db->query("select doc_id from lastmodified order by doc_id desc limit 1");    if(!sizeof(a))    return 0; -  else +     return (int)a[0]->doc_id;    }   };      _WhiteFish.DateSet get_global_dateset()   {    int max_doc_id = get_max_doc_id();    if(max_doc_id == dateset_cache_max_doc_id)    return dateset_cache; -  else -  { +     Sql.Sql db = get_db();    array a = db->query("select doc_id,at from lastmodified where "    "doc_id > %d order by doc_id asc", dateset_cache_max_doc_id);       dateset_cache_max_doc_id = max_doc_id;    if(!dateset_cache)    dateset_cache = _WhiteFish.DateSet();    dateset_cache->add_many( (array(int))a->doc_id,    (array(int))a->at );    return dateset_cache;   } - } +       protected   {    _WhiteFish.DateSet publ_dateset_cache;    int publ_dateset_cache_max_doc_id = -1;   };      _WhiteFish.DateSet get_global_publ_dateset()   {    int max_doc_id = get_max_doc_id();    if(max_doc_id == publ_dateset_cache_max_doc_id)    return publ_dateset_cache; -  else -  { +     Sql.Sql db = get_db();    array(mapping(string:mixed)) a =    db->query("SELECT doc_id, value FROM metadata "    " WHERE name = 'publish-time' "    " AND doc_id > %d ORDER BY doc_id ASC",    publ_dateset_cache_max_doc_id);       publ_dateset_cache_max_doc_id = max_doc_id;    if(!publ_dateset_cache)    publ_dateset_cache = _WhiteFish.DateSet();    publ_dateset_cache->add_many( (array(int))a->doc_id,    (array(int))a->value );    return publ_dateset_cache;   } - } +       // ----------------------------------------------   // Link handling   // ----------------------------------------------      void add_links(Standards.URI|string uri,    void|string language,    array(Standards.URI|string) links)   {    if(!links || !sizeof(links))
pike.git/lib/modules/Search.pmod/Database.pmod/MySQL.pike:1388:    db->query(" SELECT word, " +    (supports_padded_blobs() ?    " SUM(used_len) / 5 AS c " :    " SUM(LENGTH(hits)) / 5 AS c ") +    " FROM word_hit "    " GROUP BY word "    " ORDER BY c DESC "    " LIMIT %d", count || 10);       if(!sizeof(a)) -  return ({ }); -  else +  return ({});    return Array.transpose( ({ map(a->word, my_denormalize),    (array(int))a->c }) );   }      void list_url_by_prefix(string url_prefix, function(string:void) cb)   {    Sql.Sql db = get_db();    Sql.Result q =    db->big_query("SELECT uri "    " FROM uri "    " WHERE uri LIKE '"+db->quote(url_prefix)+"%'");    for(;;) {    array row = q->fetch_row();    if(!row)    break;    cb(row[0]);    }   }