public void IndexPageItems(IEnumerable <IndexingQueueItem> queueItems) { var groupedByLanguage = queueItems .Where(i => !i.Equals(IndexingQueueItem.Empty)) .GroupBy(i => i.Language) .Where(grouping => !string.IsNullOrWhiteSpace(grouping.Key)); foreach (IGrouping <string, IndexingQueueItem> grouping in groupedByLanguage) { Index index = this.Client.InitIndex(this.GetPagesIndexName(grouping.Key)); Language language = Language.Parse(grouping.Key); List <JObject> objectsToUpdate = new List <JObject>(); List <string> objectsToDelete = new List <string>(); foreach (IndexingQueueItem indexingQueueItem in grouping) { if (indexingQueueItem.Deleted) { objectsToDelete.Add(this.crawler.GetObjectId(indexingQueueItem.Id)); } else { Item item = this.database.GetItem(ID.Parse(indexingQueueItem.Id), language); if (item != null && item.Versions.Count > 0) { objectsToUpdate.Add(this.crawler.GetJsonForItem(item)); } } } index.AddObjects(objectsToUpdate); index.DeleteObjects(objectsToDelete); } }
private void IndexPageItems(IEnumerable <IndexingQueueItem> queueItems, Index index, string languageName) { Language language = Language.Parse(languageName); List <JObject> objectsToUpdate = new List <JObject>(); List <string> objectsToDelete = new List <string>(); foreach (IndexingQueueItem indexingQueueItem in queueItems) { if (indexingQueueItem.Deleted) { objectsToDelete.Add(this.crawler.GetObjectId(indexingQueueItem.Id)); } else { Item item = this.database.GetItem(ID.Parse(indexingQueueItem.Id), language); if (item != null && item.Versions.Count > 0) { objectsToUpdate.Add(this.crawler.GetJsonForItem(item)); } } } index.AddObjects(objectsToUpdate); index.DeleteObjects(objectsToDelete); }
public void TaskAddObjects() { clearTest(); List <JObject> objs = new List <JObject>(); objs.Add(JObject.Parse(@"{""firstname"":""Roger"", ""lastname"":""Barninger""}")); objs.Add(JObject.Parse(@"{""firstname"":""Roger"", ""lastname"":""Speach""}")); var task = _index.AddObjects(objs); _index.WaitTask(task["taskID"].ToString()); var res = _index.Search(new Query("")); Assert.AreEqual(2, res["nbHits"].ToObject <int>()); Assert.AreEqual("Roger", res["hits"][0]["firstname"].ToString()); }
private void AddIndexes() { var products = db.Products; Index index = client.InitIndex("products"); index.SetSettings(JObject.Parse(@"{""searchableAttributes"":[""Name"", ""Prise""]}")); List <JObject> objs = new List <JObject>(); foreach (var item in products) { objs.Add(JObject.Parse(item.ToString())); } var res = index.AddObjects(objs); System.Diagnostics.Debug.WriteLine(res); }