Skip to content

Commit

Permalink
Improvement code robutness
Browse files Browse the repository at this point in the history
  • Loading branch information
Songkai.Tang committed Dec 11, 2018
1 parent 33bad77 commit 2661da1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 0 additions & 1 deletion OneNotePageSearcher/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<appSettings>
<add key="LastIndexTime" value="1997-06-18T08:56:47.000Z" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<system.web>
Expand Down
9 changes: 9 additions & 0 deletions OneNotePageSearcher/NetLuceneProvider.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Lucene.Net.Analysis;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.QueryParsers;
using Lucene.Net.Search;
using Lucene.Net.Store;
using Directory = Lucene.Net.Store.Directory;
using Version = Lucene.Net.Util.Version;


Expand Down Expand Up @@ -160,6 +163,12 @@ private void AddTextToIndex(string pageID, string paraID, string text)
doc.Add(new Field("postBody", text, Field.Store.YES, Field.Index.ANALYZED));
writer.AddDocument(doc);
}

public string GetLastUpdatedTime()
{
var fileList = new DirectoryInfo(_indexPath).GetFiles();
return fileList.Any() ? fileList.Min(file => file.LastWriteTime).ToString("yyyy-MM-ddTHH:mm:ss.fffK") : "1978-06-18T08:56:47.000Z";
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion OneNotePageSearcher/OneNoteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,8 @@ public void GetUpdateIndexID(out HashSet<String> indexIDToDelete, out HashSet<St
}

// We also want to find page that is updated and created
string oldTime = UserSettings.ReadSetting("LastIndexTime") ?? "1978-06-18T08:56:47.000Z";
// DateTime.Now.ToString("yyyy’-‘MM’-‘dd’T’HH’:’mm’:’ss.fffK")
string oldTime = UserSettings.ReadSetting("LastIndexTime") ?? lucene.GetLastUpdatedTime();
if (isDebug) Console.WriteLine(oldTime);
foreach (var n in pageList)
{
Expand Down

0 comments on commit 2661da1

Please sign in to comment.