Hi for me its not updating properly.
Actually my scenario is,
i will have common storage folder like c:\DocumentStorage .For example, this folder has file1,file2 and file3,file4.
file1 and file2 will be belongs to Project1 and file3 and 4 belongs to project2.
i will do filter on documents and create a index like,
c:\indexstore\project1
so this index will has file1 and file2 only.
I have a common function to create and update index.
First time the following code will make an index @“c:\indexstore\project1” and do search
function search()
{
string indexFolder = @“c:\indexstore\project1”;
string documentFolder = @“C:\DocumentStorage ”;
string query = “son”;
Index index = new Index(indexFolder);
index.Add(documentFolder);
SearchResult searchResult = index.Search(query);
}
this result is correct and coming properly.
Again i’m adding a new file(file5) into string documentFolder = @“C:\DocumentStorage
consider this file5 is also belongs to project1
Second time I’m calling the same function .so this time i should not create an index.
here i need to check if index already there need to update it.
in this case how can i make update is possible?
function search()
{
string indexFolder = @“c:\indexstore\project1”;
string documentFolder = @“C:\DocumentStorage ”;
string query = “son”;
Index index = new Index(indexFolder);
index.Add(documentFolder);
SearchResult searchResult = index.Search(query);
}
i hope you understand my expectation.i will share my complete code for your reference.
//path settings
string indexFolder = “c:\IndexStore\”;
string documentsFolder = “c:\DocumentStore\”;
if (Directory.Exists(indexFolder) == false)
{
Directory.CreateDirectory(indexFolder);
}
//index settings AutoDetectEncoding
IndexSettings settings = new IndexSettings();
settings.AutoDetectEncoding = true;
//index class with async option
Index index = new Index(indexFolder, settings);
IndexingOptions options = new IndexingOptions();
options.IsAsync = true;
//Creating an Indexing
string[] files = System.IO.Directory.GetFiles(indexFolder, "*.body");
if (files.Length == 0)
{
index.Add(documentsFolder);
}
else
{
UpdateOptions updateOptions = new UpdateOptions();
updateOptions.Threads = 1;
index.Update(updateOptions);
MergeOptions mergeOptions = new MergeOptions();
mergeOptions.Cancellation = new Cancellation();
mergeOptions.Cancellation.CancelAfter(1200000); // Setting maximum duration of the operation to 30 seconds
index.Optimize(mergeOptions);
}
//Search Results
SearchResult searchResult = index.Search(findText);
kindly check and correct me if anything wrong.
deleting directory and re- creating directory for storing index will work and provides result with all newly added documents.
but this will not make sense when i deal with large volume of documents.
The above query is one possibility i'm looking for.
and the second possibility i'm looking for is,
when i upload document into documentstorage path,that time need to check whether index is available or not.
if index available need to update else create new index .
when i do search by typing keyword in another end,need to refer the indexed path and search keyword from that.
These 2 cases not a sequential work as like console app..Index creation and update needs to happen in one end and search will happen in another end