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.
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.
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.
@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.
For your case, it is necessary to change sequence of actions in the code:
Creating an index.
Setting up dictionaries.
Indexing.
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.
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.