Difficulty in searching with special characters

Hi,

I am using GroupDocs.Search to perform a content search from my documents.
The issue is I want to search text “SO(FOOD)” or “#toptrends” as a whole word. I am able to search this text as a file name but not if this particular search text appears in the content. As it contains special characters, It should give results if this search text appears as a part of the file name or appears as content.

Is there any way to search this whole text?

Thanks.

1 Like

@Hamdah

Please take a look at the following threads:

You may need to explore this documentation article as well.
Please let us know if you still need any further assistance or if issue persists.

Thank you for your quick response. I have explored the documentation as well and the code I am using is as follows, it is not giving me the required results:

        var settings = new IndexSettings
        {
            UseRawTextExtraction = false
        };

        const string indexFolder = @"D:\R_n_D\Code\GroupDocs\GettingStarted5\GettingStarted5\HelloWorld1";
        const string documentsFolder = @"D:\R_n_D\Code\GroupDocs\Documents";

        var index = new GroupDocs.Search.Index(indexFolder, settings);
        index.Add(documentsFolder);
        var option = new UpdateOptions
        {
            Threads = 2
        };
        index.Update(option); // Updating the index
        index.Dictionaries.Alphabet.SetRange(new[] { '&' }, CharacterType.Letter);
        index.Dictionaries.Alphabet.SetRange(new[] { '/' }, CharacterType.Letter);
        index.Dictionaries.Alphabet.SetRange(new[] { '(' }, CharacterType.Letter);
        index.Dictionaries.Alphabet.SetRange(new[] { ')' }, CharacterType.Letter);

        var word = new StringBuilder("ASSET(FOOD)");
        const string specialCharacters = "():\"&/|!^~*?\\";
        for (var i = word.Length - 1; i >= 0; i--)
        {
            var c = word[i];
            if (specialCharacters.Contains(c.ToString()))
            {
                word.Insert(i, @"\");
            }
        }
        var query = word.ToString();
        if (query.Contains(" "))
        {
            query = "\"" + query + "\"";
        }

        var result = index.Search(query);

it should give the document in a result which is also attached, as the query appears in the document name.

ASSET(FOOD)-16946256316557034-2023_Petty Cash Replenishment_638299661311804907.pdf (28.2 KB)

else, if I search the word “#toptrends” and use the above-mentioned code. The following document attached, must appear in search results as the word appears in the content of the document.

Hello(WORLD)-89.docx (11.5 KB)

1 Like

@Hamdah
Thanks for sharing the details. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): SEARCHNET-2922

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@Hamdah

For your case, it is necessary to change sequence of actions in the code:

  1. Creating an index.
  2. Setting up dictionaries.
  3. Indexing.
  4. Searching.
// Create a new GroupDocs.Search Index object with the specified index folder and settings.
var index = new GroupDocs.Search.Index(indexFolder, settings, true);

// Define custom character ranges for the alphabet dictionaries to include special characters as letters.
// This allows these characters to be searchable.
index.Dictionaries.Alphabet.SetRange(new[] { '&' }, CharacterType.Letter); // Include '&' as a letter.
index.Dictionaries.Alphabet.SetRange(new[] { '/' }, CharacterType.Letter); // Include '/' as a letter.
index.Dictionaries.Alphabet.SetRange(new[] { '(' }, CharacterType.Letter); // Include '(' as a letter.
index.Dictionaries.Alphabet.SetRange(new[] { ')' }, CharacterType.Letter); // Include ')' as a letter.

// Add documents from the specified documents folder to the search index.
index.Add(documentsFolder);

Please try the above code and let us know if issue persists.

Still, the issue persists with the search query ‘#toptrends’. It is not giving the required results.

@Hamdah

We’ll further look into this scenario and notify you about the outcomes.

@Hamdah

Please make sure you have a valid license. You can avail a temporary license as well.
It is necessary to add this code:

index.Dictionaries.Alphabet.SetRange(new[] { '#' }, CharacterType.Letter);

Or with only one line:

index.Dictionaries.Alphabet.SetRange(new[] { '&', '/', '(', ')', '#' }, CharacterType.Letter);

Yes, I have a valid license and using the line of code that you have mentioned but still have no success.

@Hamdah

Please share a console application using that issue could be reproduced. It’d be great if you could share a screencast/short video explaining the steps to reproduce the issue as well.