We're sorry GroupDocs doesn't work properply without JavaScript enabled.

Free Support Forum - groupdocs.com

Search API is not returning any document in .NET

I am performing a simple search and the code is not returning any documents. Can you tell me what is wrong?

1 Like

@nsanoir,

Can you please share the sample code or application that you are using? Also specify the API version (e.g. 19.5, 19.10) that you integrated in the application. We’ll surely then help you out.

Version 19.10
strFind = WISInput.Text;
string query = strFind;
Index index = new Index(indexFolder);
IndexingOptions optionsIndex = new IndexingOptions();
optionsIndex.IsAsync = true;
index.Add(dataDir, optionsIndex);
SearchResult result = index.Search(query);

lblMessage.Text = "Matches: " + result.DocumentCount;
for (int i = 0; i < result.DocumentCount; i++)
{
FoundDocument document = result.GetFoundDocument(i);
changedFiles.Add(document.DocumentInfo.FilePath);
}

Session.Add(“ChangeFilesList”, changedFiles);
if ((changedFiles != null) && (!changedFiles.Any()))
{
ClearBtn.Visible = false;

}
else
{
ClearBtn.Visible = true;

}
WISInput.Text = string.Empty;
WISInput.Visible = false;

@nsanoir,

We are not able to reproduce this issue using code below (that’s the most simplified code tested in a console application):

string indexFolder = "index path";
string documentsFolder = "documents path";
// Creating an index in the specified folder
Index index = new Index(indexFolder);
// Indexing documents from the specified folder
IndexingOptions optionsIndex = new IndexingOptions();
optionsIndex.IsAsync = true;
index.Add(documentsFolder);
// Search with text query
SearchResult result = index.Search("LOREM");
// Printing the result
Console.WriteLine("Documents found: " + result.DocumentCount);
Console.WriteLine("Total occurrences found: " + result.OccurrenceCount);
for (int i = 0; i < result.DocumentCount; i++)
{
    FoundDocument document = result.GetFoundDocument(i);
    Console.WriteLine("\tDocument: " + document.DocumentInfo.FilePath);
    Console.WriteLine("\tOccurrences: " + document.OccurrenceCount);
} 

Can you please share your project (along-with index and documents path)? We will investigate that. Please don’t share license file in the project.

Does running the above code cause the indexes to be created over and over again each time the code is run? We have thousands of documents and the search is taking a long time.

Basically, how to check if index exist, so the index isn’t recreated each time the code runs.

@nsanoir

You can check if the index is already created for a folder. From an index, you can get a list of indexed paths (folders or files):
string[] indexedPaths = index.GetIndexedPaths();
And then you can compare the folder path with the indexed paths.