Text search is not working

The following code is not returning any documents:

static void Main(string[] args)
{
string LicensePath = @“C:\license\GroupDocs.Search.lic”;
GroupDocs.Search.License lic = new GroupDocs.Search.License();

        //Set license
        lic.SetLicense(LicensePath);


        string indexFolder = "c:\\myindex";
        string documentsFolder = "c:\\Test\\WorkItem";
        // 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, optionsIndex);
        // Search with text query
        SearchResult result = index.Search("technical");
        // 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);
        }

    }
1 Like

@nsanoir

This issue is reproduced at our end. Hence, we’ve logged it in our internal bug reporting system. It’ll be now further investigated. Your issue ticket ID is SEARCHNET-2560.

@nsanoir

The issue is when asynchronous indexing is enabled (optionsIndex.IsAsync = true;), the index.Add() method completes before indexing is complete.
And that is, when index.Search() is called, there is no indexed data in the index yet. When you use asynchronous indexing, you should track completion with index.Events.OperationFinished event, or StatusChanged event, or OperationProgressChanged event.

Can you provide me with a code sample? Thanks

@nsanoir

Please have a look at this documentation article. Let us know if you still need further help.

I run the following code and I still get no documents returned:

static void Main(string[] args)
{
string LicensePath = @“C:\license\GroupDocs.Search.lic”;
GroupDocs.Search.License lic = new GroupDocs.Search.License();

        //Set license
        lic.SetLicense(LicensePath);


        string indexFolder = "c:\\myindex";
        string documentsFolder = "c:\\Test\\WorkItem";
        // Creating an index in the specified folder
        Index index = new Index(indexFolder);
        // Indexing documents from the specified folder
        index.Events.OperationFinished += (s, arg) =>
        {
            Console.WriteLine("Operation finished: " + arg.OperationType);
            Console.WriteLine("Message: " + arg.Message);
            Console.WriteLine("Index folder: " + arg.IndexFolder);
            Console.WriteLine("Time: " + arg.Time);


        };

        IndexingOptions optionsIndex = new IndexingOptions();
        optionsIndex.IsAsync = true;
        index.Add(documentsFolder, optionsIndex);
        // Search with text query
        SearchResult result = index.Search("technical");
        // 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);
        }

    }
1 Like

@nsanoir

We’re further looking into this scenario. You’ll be notified about the outcomes.

@nsanoir

Please try the following code and let us know if issue persists. Following code uses asynchronous indexing:

string indexFolder = @"C:\MyIndex";
string documentsFolder = @"C:\MyDocuments";

// Creating an index in the specified folder
Index index = new Index(indexFolder);

// Creating a gate for the current thread
ManualResetEvent gate = new ManualResetEvent(false);

// Indexing documents from the specified folder
index.Events.OperationFinished += (s, arg) =>
{
    Console.WriteLine("Operation finished: " + arg.OperationType);
    Console.WriteLine("Message: " + arg.Message);
    Console.WriteLine("Index folder: " + arg.IndexFolder);
    Console.WriteLine("Time: " + arg.Time);

    if (arg.Status == IndexStatus.Ready)
    {
        // Opening the gate
        gate.Set();
    }
};

IndexingOptions optionsIndex = new IndexingOptions();
optionsIndex.IsAsync = true;
index.Add(documentsFolder, optionsIndex);

// Waiting for call to gate.Set()
gate.WaitOne();

// Search with text query
SearchResult result = index.Search("technical");
// 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);
}

Documents are now being returned. Thank you

1 Like

@nsanoir

You’re welcome.