private static void _addToLuceneIndex(Models.DocumentModel document, IndexWriter writer)
        {
            // remove older index entry
            var searchQuery = new TermQuery(new Term("Id", document.Id.ToString()));

            writer.DeleteDocuments(searchQuery);

            // add new index entry
            var doc = new Document();

            // add lucene fields mapped to db fields
            doc.Add(new Field("Id", document.Id.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field("Title", document.Title, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("Description", document.Description, Field.Store.YES, Field.Index.ANALYZED));
            doc.Add(new Field("Author", document.Author, Field.Store.YES, Field.Index.ANALYZED));

            // add entry to index
            writer.AddDocument(doc);
        }
Example #2
0
        public static void AddDocument(string path)
        {
            var extractor = new TikaOnDotNet.TextExtraction.TextExtractor();
            var result    = extractor.Extract(path);

            string description = result.Metadata?.FirstOrDefault(x => x.Key.ToLower() == "description").Value; //pobiera wartoĊ›ci z metadanych
            string author      = result.Metadata?.FirstOrDefault(x => x.Key.ToLower() == "author").Value;
            string title       = result.Metadata?.FirstOrDefault(x => x.Key.ToLower() == "title").Value;

            var document = new Models.DocumentModel()
            {
                FileName    = Path.GetFileName(path),
                Author      = (author == null) ? "": author,
                Description = (description == null) ? "" : description,
                Title       = (title == null) ? "" : title
            };

            using (var db = new DocumentDbContext())
            {
                db.Documents.Add(document);
                db.SaveChanges();
            }
            Services.LuceneSearch.AddUpdateLuceneIndex(document);
        }
 public static void AddUpdateLuceneIndex(Models.DocumentModel document)
 {
     AddUpdateLuceneIndex(new List <Models.DocumentModel> {
         document
     });
 }
        public ActionResult HandleDocumentRadio(int SelectedDocument, int Id)
        {
            Document doc = DocumentHelper.Instance.GetDocument(SelectedDocument);

            Models.DocumentModel dm = new Models.DocumentModel();

            dm.Name = doc.Name;
            dm.Id = doc.Id;

            dm.Customer = doc.Customer;
            dm.Customers = CustomerHelper.Instance.GetAllCustomers();

            dm.Folder = doc.Folder;
            dm.Folders = FolderHelper.Instance.GetAllFolders();

            return View("./../Document/ManageDocument", dm);
        }