public void Can_modify_doc_in_index_and_retrieve_by_secondary_key() { var index = new TestIndex(); var doc = new XDoc("doc").Elem("foo", "bar"); var d = new Document(); d.Add(new Field("id", "123", Field.Store.YES, Field.Index.UN_TOKENIZED)); d.Add(new Field("doc", doc.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED)); d.Add(new Field("foo", "bar", Field.Store.NO, Field.Index.ANALYZED)); index.Add(d); var hits = index.Search(index.Parse("foo:bar")); Assert.AreEqual(1, hits.Count()); var d2 = hits.First().Document; Assert.AreEqual("123", d2.Get("id")); Assert.AreEqual(doc.ToString(), d2.Get("doc")); d2.RemoveField("doc"); d2.RemoveField("foo"); doc = new XDoc("doc").Elem("foo", "baz"); d2.Add(new Field("doc", doc.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED)); d2.Add(new Field("foo", "baz", Field.Store.NO, Field.Index.ANALYZED)); index.Update(new Term("id", "123"), d2); hits = index.Search(index.Parse("foo:baz")); Assert.AreEqual(1, hits.Count()); var d3 = hits.First().Document; Assert.AreEqual("123", d3.Get("id")); Assert.AreEqual(doc.ToString(), d3.Get("doc")); }
public void Can_modify_doc_in_index_and_retrieve_by_secondary_key() { var index = new TestIndex(); var doc = new XDoc("doc").Elem("foo", "bar"); var d = new Document(); d.Add(new Field("id", "123", Field.Store.YES, Field.Index.UN_TOKENIZED)); d.Add(new Field("doc", doc.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED)); d.Add(new Field("foo", "bar", Field.Store.NO, Field.Index.ANALYZED)); index.Add(d); var hits = index.Search(index.Parse("foo:bar")); Assert.AreEqual(1, hits.Count()); var d2 = hits.First().Document; Assert.AreEqual("123", d2.Get("id")); Assert.AreEqual(doc.ToString(), d2.Get("doc")); d2.RemoveField("doc"); d2.RemoveField("foo"); doc = new XDoc("doc").Elem("foo", "baz"); d2.Add(new Field("doc", doc.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED)); d2.Add(new Field("foo", "baz", Field.Store.NO, Field.Index.ANALYZED)); index.Update(new Term("id", "123"), d2); hits = index.Search(index.Parse("foo:baz")); Assert.AreEqual(1, hits.Count()); var d3 = hits.First().Document; Assert.AreEqual("123", d3.Get("id")); Assert.AreEqual(doc.ToString(), d3.Get("doc")); }
public void Can_use_update_for_new_document() { var index = new TestIndex(); var doc = new XDoc("doc").Elem("foo", "bar"); var d = new Document(); d.Add(new Field("id", "123", Field.Store.YES, Field.Index.UN_TOKENIZED)); d.Add(new Field("doc", doc.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED)); d.Add(new Field("foo", "bar", Field.Store.NO, Field.Index.ANALYZED)); index.Update(new Term("id", "123"), d); var hits = index.Search(index.Parse("foo:bar")); Assert.AreEqual(1, hits.Count()); var d2 = hits.First().Document; Assert.AreEqual("123", d2.Get("id")); }
public void Update_does_not_keep_unstored_fields() { var index = new TestIndex(); var doc = new XDoc("doc").Elem("foo", "bar"); var d = new Document(); d.Add(new Field("id", "123", Field.Store.YES, Field.Index.UN_TOKENIZED)); d.Add(new Field("doc", doc.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED)); d.Add(new Field("foo", "bar", Field.Store.NO, Field.Index.ANALYZED)); index.Add(d); var hits = index.Search(index.Parse("foo:bar")); Assert.AreEqual(1, hits.Count()); var d2 = hits.First().Document; index.Update(new Term("id", "123"), d2); hits = index.Search(index.Parse("foo:bar")); Assert.AreEqual(0, hits.Count()); }
public void Can_use_update_for_new_document() { var index = new TestIndex(); var doc = new XDoc("doc").Elem("foo", "bar"); var d = new Document(); d.Add(new Field("id", "123", Field.Store.YES, Field.Index.UN_TOKENIZED)); d.Add(new Field("doc", doc.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED)); d.Add(new Field("foo", "bar", Field.Store.NO, Field.Index.ANALYZED)); index.Update(new Term("id", "123"), d); var hits = index.Search(index.Parse("foo:bar")); Assert.AreEqual(1, hits.Count()); var d2 = hits.First().Document; Assert.AreEqual("123", d2.Get("id")); }
public void Update_does_not_keep_unstored_fields() { var index = new TestIndex(); var doc = new XDoc("doc").Elem("foo", "bar"); var d = new Document(); d.Add(new Field("id", "123", Field.Store.YES, Field.Index.UN_TOKENIZED)); d.Add(new Field("doc", doc.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED)); d.Add(new Field("foo", "bar", Field.Store.NO, Field.Index.ANALYZED)); index.Add(d); var hits = index.Search(index.Parse("foo:bar")); Assert.AreEqual(1, hits.Count()); var d2 = hits.First().Document; index.Update(new Term("id", "123"), d2); hits = index.Search(index.Parse("foo:bar")); Assert.AreEqual(0, hits.Count()); }