/// <summary> /// Add documents. /// </summary> /// <param name="writer">The index writer.</param> /// <param name="directoryInfo">The directory information where all the files that are to be added are located.</param> /// <param name="documents">The supported documents search filter, used to indicate what files are to be added.</param> public void AddDocuments(Lucene.Net.Index.IndexWriter writer, DirectoryInfo directoryInfo, SupportedDocumentExtension documents) { Nequeo.IO.Directory directory = new Nequeo.IO.Directory(); // Select the document format filter. // If html has been selected. if (documents.SupportedDocuments.HasFlag(SupportedDocuments.Html)) { // Create the html filter. HtmlFilter htmlFilter = new HtmlFilter(); string[] files = directory.GetFiles(directoryInfo.FullName, documents.GetFormattedSearchPatterns(SupportedDocuments.Html)); htmlFilter.AddDocuments(writer, directoryInfo, files, documents); } // If pdf has been selected. if (documents.SupportedDocuments.HasFlag(SupportedDocuments.Pdf)) { // Create the pdf filter. PdfFilter pdfFilter = new PdfFilter(); string[] files = directory.GetFiles(directoryInfo.FullName, documents.GetFormattedSearchPatterns(SupportedDocuments.Pdf)); pdfFilter.AddDocuments(writer, directoryInfo, files, documents); } // If rtf has been selected. if (documents.SupportedDocuments.HasFlag(SupportedDocuments.Rtf)) { // Create the rtf filter. RtfFilter rtfFilter = new RtfFilter(); string[] files = directory.GetFiles(directoryInfo.FullName, documents.GetFormattedSearchPatterns(SupportedDocuments.Rtf)); rtfFilter.AddDocuments(writer, directoryInfo, files, documents); } // If txt has been selected. if (documents.SupportedDocuments.HasFlag(SupportedDocuments.Txt)) { // Create the txt filter. TxtFilter txtFilter = new TxtFilter(); string[] files = directory.GetFiles(directoryInfo.FullName, documents.GetFormattedSearchPatterns(SupportedDocuments.Txt)); txtFilter.AddDocuments(writer, directoryInfo, files, documents); } // If xml has been selected. if (documents.SupportedDocuments.HasFlag(SupportedDocuments.Xml)) { // Create the xml filter. XmlFilter xmlFilter = new XmlFilter(); string[] files = directory.GetFiles(directoryInfo.FullName, documents.GetFormattedSearchPatterns(SupportedDocuments.Xml)); xmlFilter.AddDocuments(writer, directoryInfo, files, documents); } // If docx has been selected. if (documents.SupportedDocuments.HasFlag(SupportedDocuments.Docx)) { // Create the docx filter. MSDocFilter docxFilter = new MSDocFilter(); string[] files = directory.GetFiles(directoryInfo.FullName, documents.GetFormattedSearchPatterns(SupportedDocuments.Docx)); docxFilter.AddDocuments(writer, directoryInfo, files, documents); } }
/// <summary> /// Add text to the existing index. /// </summary> /// <param name="writer">The index writer.</param> /// <param name="facetWriter">The facet index writer.</param> /// <param name="addFileData">The file data to add.</param> /// <param name="config">The facet configuration information.</param> public void AddFile(Lucene.Net.Index.IndexWriter writer, DirectoryTaxonomyWriter facetWriter, Dictionary <FacetField, FileFacetModel> addFileData, FacetsConfig config) { Nequeo.IO.Directory directory = new Nequeo.IO.Directory(); // For each file facet. foreach (KeyValuePair <FacetField, FileFacetModel> item in addFileData) { // Select the document format filter. // If html has been selected. if (item.Value.Documents.SupportedDocuments.HasFlag(SupportedDocuments.Html)) { // Create the html filter. HtmlFilter htmlFilter = new HtmlFilter(); string[] files = directory.GetFiles(item.Value.DirectoryInfo.FullName, item.Value.Documents.GetFormattedSearchPatterns(SupportedDocuments.Html)); htmlFilter.AddDocuments(writer, facetWriter, item.Value.DirectoryInfo, files, item.Value.Documents, item.Key, config); } // If pdf has been selected. if (item.Value.Documents.SupportedDocuments.HasFlag(SupportedDocuments.Pdf)) { // Create the pdf filter. PdfFilter pdfFilter = new PdfFilter(); string[] files = directory.GetFiles(item.Value.DirectoryInfo.FullName, item.Value.Documents.GetFormattedSearchPatterns(SupportedDocuments.Pdf)); pdfFilter.AddDocuments(writer, facetWriter, item.Value.DirectoryInfo, files, item.Value.Documents, item.Key, config); } // If rtf has been selected. if (item.Value.Documents.SupportedDocuments.HasFlag(SupportedDocuments.Rtf)) { // Create the rtf filter. RtfFilter rtfFilter = new RtfFilter(); string[] files = directory.GetFiles(item.Value.DirectoryInfo.FullName, item.Value.Documents.GetFormattedSearchPatterns(SupportedDocuments.Rtf)); rtfFilter.AddDocuments(writer, facetWriter, item.Value.DirectoryInfo, files, item.Value.Documents, item.Key, config); } // If txt has been selected. if (item.Value.Documents.SupportedDocuments.HasFlag(SupportedDocuments.Txt)) { // Create the txt filter. TxtFilter txtFilter = new TxtFilter(); string[] files = directory.GetFiles(item.Value.DirectoryInfo.FullName, item.Value.Documents.GetFormattedSearchPatterns(SupportedDocuments.Txt)); txtFilter.AddDocuments(writer, facetWriter, item.Value.DirectoryInfo, files, item.Value.Documents, item.Key, config); } // If xml has been selected. if (item.Value.Documents.SupportedDocuments.HasFlag(SupportedDocuments.Xml)) { // Create the xml filter. XmlFilter xmlFilter = new XmlFilter(); string[] files = directory.GetFiles(item.Value.DirectoryInfo.FullName, item.Value.Documents.GetFormattedSearchPatterns(SupportedDocuments.Xml)); xmlFilter.AddDocuments(writer, facetWriter, item.Value.DirectoryInfo, files, item.Value.Documents, item.Key, config); } // If docx has been selected. if (item.Value.Documents.SupportedDocuments.HasFlag(SupportedDocuments.Docx)) { // Create the docx filter. MSDocFilter docxFilter = new MSDocFilter(); string[] files = directory.GetFiles(item.Value.DirectoryInfo.FullName, item.Value.Documents.GetFormattedSearchPatterns(SupportedDocuments.Docx)); docxFilter.AddDocuments(writer, facetWriter, item.Value.DirectoryInfo, files, item.Value.Documents, item.Key, config); } } }