/// <summary> /// Load data directly from lucene document /// </summary> /// <param name="doc"></param> public SbSearchDoc(Lucene.Net.Documents.Document doc) { ContentTypes = doc.GetValues("type"); Sources = doc.GetValues("source"); Categories = doc.GetValues("category"); try { LastModified = DateTimeEx.FromUnixTimestamp(Convert.ToInt32(doc.Get("lastmod"))); } catch { LastModified = DateTime.MinValue; } Title = doc.Get("title"); Keywords = doc.Get("keywords"); Description = doc.Get("desc"); Author = doc.Get("author"); Location = doc.Get("loc"); // PlainContent = doc.Get("content"); }
private void DoAssert(Lucene.Net.Documents.Document doc, bool fromIndex) { System.String[] keywordFieldValues = doc.GetValues("keyword"); System.String[] textFieldValues = doc.GetValues("text"); System.String[] unindexedFieldValues = doc.GetValues("unindexed"); System.String[] unstoredFieldValues = doc.GetValues("unstored"); Assert.IsTrue(keywordFieldValues.Length == 2); Assert.IsTrue(textFieldValues.Length == 2); Assert.IsTrue(unindexedFieldValues.Length == 2); // this test cannot work for documents retrieved from the index // since unstored fields will obviously not be returned if (!fromIndex) { Assert.IsTrue(unstoredFieldValues.Length == 2); } Assert.IsTrue(keywordFieldValues[0].Equals("test1")); Assert.IsTrue(keywordFieldValues[1].Equals("test2")); Assert.IsTrue(textFieldValues[0].Equals("test1")); Assert.IsTrue(textFieldValues[1].Equals("test2")); Assert.IsTrue(unindexedFieldValues[0].Equals("test1")); Assert.IsTrue(unindexedFieldValues[1].Equals("test2")); // this test cannot work for documents retrieved from the index // since unstored fields will obviously not be returned if (!fromIndex) { Assert.IsTrue(unstoredFieldValues[0].Equals("test1")); Assert.IsTrue(unstoredFieldValues[1].Equals("test2")); } }