private void Update(LuceneIndexItem data, LuceneController storeInstance) { if (null == data) { throw new ArgumentNullException("data"); } Delete(data, storeInstance); Add(data, storeInstance); }
private void Add(LuceneIndexItem data, LuceneController storeInstance) { if (null == data) { throw new ArgumentNullException("data"); } FieldConfig indexJson = FilesRepository.GetIndexConfig(data.PortalId); Store.Add(LuceneMappingUtils.CreateLuceneDocument(data, indexJson)); }
private void Delete(LuceneIndexItem data, LuceneController storeInstance) { if (data == null) { throw new ArgumentNullException("data"); } Query deleteQuery = LuceneMappingUtils.GetDeleteQuery(data); if (storeInstance == null) { Store.Delete(deleteQuery); } else { storeInstance.Store.Delete(deleteQuery); } }
/// ----------------------------------------------------------------------------- /// <summary> /// Returns the collection of SearchDocuments populated with Tab MetaData for the given portal. /// </summary> /// <param name="portalId"></param> /// <param name="startDateLocal"></param> /// <returns></returns> /// <history> /// [vnguyen] 04/16/2013 created /// </history> /// ----------------------------------------------------------------------------- public IEnumerable<LuceneIndexItem> GetPortalSearchDocuments(int portalId, DateTime? startDateLocal) { var searchDocuments = new List<LuceneIndexItem>(); var folderManager = FolderManager.Instance; var folder = folderManager.GetFolder(portalId, ""); var files = folderManager.GetFiles(folder, true); if (startDateLocal.HasValue) { files = files.Where(f => f.LastModifiedOnDate > startDateLocal.Value); } try { foreach (var file in files) { var custom = GetCustomFileData(file); var indexData = new LuceneIndexItem() { PortalId = portalId, FileId = file.FileId, FileName = file.FileName, Folder = file.Folder.TrimEnd('/'), Title = custom["Title"] == null ? "" : custom["Title"].ToString(), Description = custom["Description"] == null ? "" : custom["Description"].ToString(), FileContent = GetFileContent(file.FileName, file) }; if (custom["Category"] != null) { foreach (dynamic item in custom["Category"]) { indexData.Categories.Add(item); } } searchDocuments.Add(indexData); } } catch (Exception ex) { Exceptions.LogException(ex); } return searchDocuments; }
//private void Add(LuceneIndexItem data) //{ // this.Add(data, null); //} /// <summary> /// Deletes the matching objects in the IndexWriter. /// </summary> /// <param name="data"></param> public void Delete(LuceneIndexItem data) { Delete(data, null); }
public void Update(LuceneIndexItem data) { this.Delete(data, null); this.Add(data, null); }
private static string GetIndexFieldValue(LuceneIndexItem item) { return item.FileId.ToString(); }
private static void AddToLuceneIndex(LuceneIndexItem item, IndexWriter writer) { // remove older index entry var searchQuery = new TermQuery(new Term(GetIndexField(), GetIndexFieldValue(item))); writer.DeleteDocuments(searchQuery); // add new index entry var luceneDoc = new Document(); // add lucene fields mapped to db fields luceneDoc.Add(new Field("PortalId", item.PortalId.ToString(), Field.Store.NO, Field.Index.ANALYZED)); luceneDoc.Add(new Field("FileId", item.FileId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); luceneDoc.Add(new Field("FileName", item.FileName, Field.Store.NO, Field.Index.ANALYZED)); luceneDoc.Add(new Field("Folder", item.Folder, Field.Store.NO, Field.Index.ANALYZED)); if (!string.IsNullOrEmpty(item.Title)) luceneDoc.Add(new Field("Title", item.Title, Field.Store.NO, Field.Index.ANALYZED)); if (!string.IsNullOrEmpty(item.Description)) luceneDoc.Add(new Field("Description", item.Description, Field.Store.NO, Field.Index.ANALYZED)); if (!string.IsNullOrEmpty(item.FileContent)) luceneDoc.Add(new Field("FileContent", item.FileContent, Field.Store.NO, Field.Index.ANALYZED)); if (item.Categories != null) { foreach (var cat in item.Categories) { luceneDoc.Add(new Field("Category", cat, Field.Store.NO, Field.Index.ANALYZED)); } } // add entry to index try { writer.AddDocument(luceneDoc); } catch (Exception ex) { Utils.Logger.Error(string.Format("Failed to index File [{0}:{1}]", item.FileId, item.Title), ex); } }
internal static void IndexItem(LuceneIndexItem item) { IndexItem(new List<LuceneIndexItem> { item }); }