public static String indexText(String name, bool isDelete) { String url = getUrl(name); foreach (Page p in SDB.search_db.Select <Page>("from Page where url==?", url)) { engine.indexTextNoTran(SDB.search_db, commitCount, p.id, p.content.ToString(), true); engine.indexTextNoTran(SDB.search_db, commitCount, p.rankUpId(), p.rankUpDescription(), true); SDB.search_db.Delete("Page", p.id); } if (isDelete) { return("deleted"); } { Page p = Page.Get(url); if (p == null) { return("temporarily unreachable"); } else { p.id = SDB.search_db.NewId(); SDB.search_db.Insert("Page", p); engine.indexTextNoTran(SDB.search_db, commitCount, p.id, p.content.ToString(), false); engine.indexTextNoTran(SDB.search_db, commitCount, p.rankUpId(), p.rankUpDescription(), false); return(p.url); } } }
public static async Task <String> indexTextAsync(String name, bool onlyDelete) { String url = getUrl(name); { foreach (Page p in App.Auto.Select <Page>("from Page where url==?", url)) { engine.indexTextNoTran(App.Auto, commitCount, p.id, p.content.ToString(), true); engine.indexTextNoTran(App.Auto, commitCount, p.rankUpId(), p.rankUpDescription(), true); App.Auto.Delete("Page", p.id); } } if (onlyDelete) { return("deleted"); } { Page p = await Page.GetAsync(url); if (p == null) { return("temporarily unreachable"); } else { p.id = App.Auto.NewId(); App.Auto.Insert("Page", p); engine.indexTextNoTran(App.Auto, commitCount, p.id, p.content.ToString(), false); engine.indexTextNoTran(App.Auto, commitCount, p.rankUpId(), p.rankUpDescription(), false); return(p.url); } } }
//with transaction, faster private static async Task <String> indexTextWithTranAsync(String url, bool onlyDelete) { return(await pageLockAsync(url, async() => { using (var box = App.Auto.Cube()) { Page defaultPage = null; foreach (Page p in box.Select <Page>("from Page where url==?", url).ToArray()) { engine.indexText(box, p.id, p.content, true); engine.indexText(box, p.rankUpId(), p.rankUpDescription(), true); box["Page", p.id].Delete(); defaultPage = p; } if (onlyDelete) { return box.Commit() == CommitResult.OK ? "deleted" : "not deleted"; } { Page p = await Html.GetAsync(url); if (p == null) { //p = defaultPage; } if (p == null) { return "temporarily unreachable"; } else { if (p.id == 0) { p.id = box.NewId(); } box["Page"].Insert(p); engine.indexText(box, p.id, p.content, false); engine.indexText(box, p.rankUpId(), p.rankUpDescription(), false); CommitResult cr = box.Commit(); if (cr != CommitResult.OK) { return cr.GetErrorMsg(box); } return p.url; } } } })); }
//no transaction, less memory private static async Task <String> indexTextNoTranAsync(String url, bool onlyDelete) { const int commitCount = 200; return(await pageLockAsync(url, async() => { Page defaultPage = null; foreach (Page p in App.Auto.Select <Page>("from Page where url==?", url)) { engine.indexTextNoTran(App.Auto, commitCount, p.id, p.content, true); engine.indexTextNoTran(App.Auto, commitCount, p.rankUpId(), p.rankUpDescription(), true); App.Auto.Delete("Page", p.id); defaultPage = p; } if (onlyDelete) { return "deleted"; } { Page p = await Html.GetAsync(url); if (p == null) { p = defaultPage; } if (p == null) { return "temporarily unreachable"; } else { if (p.id == 0) { p.id = App.Auto.NewId(); } App.Auto.Insert("Page", p); engine.indexTextNoTran(App.Auto, commitCount, p.id, p.content, false); engine.indexTextNoTran(App.Auto, commitCount, p.rankUpId(), p.rankUpDescription(), false); return p.url; } } })); }
public static async Task <String> indexTextAsync(String name, bool onlyDelete) { String url = getUrl(name); using (var box = App.Auto.Cube()) { PageLock pl = box["PageLock", url].Select <PageLock>(); if (pl == null) { pl = new PageLock { url = url, time = DateTime.Now }; } else if ((DateTime.Now - pl.time).TotalSeconds > 120) { pl.time = DateTime.Now; } else { return("Running"); } box["PageLock"].Replace(pl); if (box.Commit() != CommitResult.OK) { return("Running"); } } try { foreach (Page p in App.Auto.Select <Page>("from Page where url==?", url)) { engine.indexTextNoTran(App.Auto, commitCount, p.id, p.content.ToString(), true); engine.indexTextNoTran(App.Auto, commitCount, p.rankUpId(), p.rankUpDescription(), true); App.Auto.Delete("Page", p.id); } if (onlyDelete) { return("deleted"); } { Page p = await Page.GetAsync(url); if (p == null) { return("temporarily unreachable"); } else { p.id = App.Auto.NewId(); App.Auto.Insert("Page", p); engine.indexTextNoTran(App.Auto, commitCount, p.id, p.content.ToString(), false); engine.indexTextNoTran(App.Auto, commitCount, p.rankUpId(), p.rankUpDescription(), false); return(p.url); } } } finally { App.Auto.Delete("PageLock", url); } }