DTSearch IndexJob Add File To Index
By Robbe Morris
The code sample below demonstrates how to add files to an index in dtsearch.
using dtSearch.Engine;
using System.IO;
using System.Text;
namespace SCSO.Search.Engine
{
public class IndexController
{
public void UpdateIndex(string indexPath, string tempFolder, List<string> filesToAdd)
{
using (var job = new IndexJob())
{
job.ActionAdd
= true;
job.IndexPath
= indexPath;
job.IndexingFlags
= IndexingFlags.dtsIndexCacheText |
IndexingFlags.dtsAlwaysAdd | IndexingFlags.dtsIndexCacheTextWithoutFields;
job.ToAddFileListName
= CreateIndexCommitFile(tempFolder, filesToAdd);
job.Execute();
}
}
private static string CreateIndexCommitFile(string tempFolder, List<string> files)
{
var fileName = Path.Combine(tempFolder,"IndexCommitFile.txt");
if (File.Exists(fileName)) File.Delete(fileName);
var sb = new StringBuilder();
foreach (var file in files)
{
sb.AppendLine(file);
}
File.WriteAllText(fileName, sb.ToString());
return fileName;
}
}
}
DTSearch IndexJob Add File To Index (700 Views)