Free Support Forum - groupdocs.com

Search a keyword in specific files using .NET

HI,I have a storage folder which contains,100 files,i did indexing of all initially and i have a requirement that i need to search particular keyword in some specific files(around 5 files) .how it is possible?

1 Like

@bharathiGK,

Currently, you can do documents filtering in search results. To specify which of the documents found should be returned as a result of the search, the SearchDocumentFilter property of the SearchOptions class is used. Please have a look at this documentation article.

We’re investigating this use-case. Your investigation ticket ID is SEARCHNET-2213. As there’s any further update, you’ll be notified.

Hi.i gone through the SearchDocumentFilter article,It not suits my requirement.
i need to filter filepath with filename.if any concept available?

1 Like

@bharathiGK,

Using following code you can do searching over specific documents:

Index index = new Index(indexFolder);
index.Add(documentFolders);
ISearchDocumentFilter filter1 = SearchDocumentFilter.CreateFilePathRegularExpression(Regex.Escape(@"DocumentFolder\Document1.txt"), RegexOptions.IgnoreCase);
ISearchDocumentFilter filter2 = SearchDocumentFilter.CreateFilePathRegularExpression(Regex.Escape(@"Document2.docx"), RegexOptions.IgnoreCase);
ISearchDocumentFilter filter3 = SearchDocumentFilter.CreateFilePathRegularExpression(Regex.Escape(@"C:\Pdf\Document2.pdf"), RegexOptions.IgnoreCase);
ISearchDocumentFilter filter = SearchDocumentFilter.CreateOr(filter1, filter2, filter3);
SearchOptions options = new SearchOptions();
options.SearchDocumentFilter = filter;

SearchResult result = index.Search("some", options);
Console.WriteLine(result.DocumentCount); 

We hope it will help you to meet your requirements.

Okay.Thank you

It Helps me. i need sample code for List of documents i need to select.

For Example - i have 10 files in one folder,i need to select only 5 files dynamically.

1 Like

@bharathiGK,

We are further investigating this scenario. As there’s any update, you’ll be notified.

@bharathiGK,

Yes, we can get a list of all the individual indexed documents:

DocumentInfo[] documents = index.GetIndexedDocuments();

Note that the GetIndexedPaths method returns all indexed paths (folders or files that have been added to the index).

Okay.Thank you.i will check.

1 Like

@bharathiGK,

You are welcome.

Hi…i have stored all files in one common folder.i am maintaining details of which document belongs to which sub folders information in database… while i start indexing i need to pass this information…how to handle this…

For example consider i stored policies.docx,Hr.pdf under documents folder.
But these files actually comes under the HrPolies folder.

I meant these documents original path from database is Documents–> HrPolies.

But documents all stored under a common folder in local storage Documents.

So when I’m creating an index I’m in a situation to segregate documents with mainfolders followed by subfolder based on database stored details

1 Like

@bharathiGK,

We are investigating this use-case/scenario. Your investigation ticket ID is SEARCHNET-2223. As there’s any update, you’ll be notified.

Hi,Can i get examples for Index Repository and how to dynamically load different index paths and Documents path.i think it may suits for time being. i’ m thinking that we can assign more index path and documents path using this repository …

i wish to have some code for dynamically pass path in c#

1 Like

@bharathiGK,

You can create multiple indexes and documents paths. Please have a look at this article. If it doesn’t fulfill you needs, please elaborate your requirements with a use-case or example.

@bharathiGK,

We’ve an update on SEARCHNET-2223.

  1. During indexing, add an additional field “Folder” to each document containing the name of the folder in the database. In this case, it will be possible to set the name of the folder in the search query (Faceted search). You may find following documentation articles helpful:
    https://docs.groupdocs.com/display/searchnet/Indexing+additional+fields
    https://docs.groupdocs.com/display/searchnet/Faceted+search
  2. During or after indexing, set an attribute with the name of the folder from the database for each document. In this case, during the search, it will be possible to set a filter by attribute name.
    https://docs.groupdocs.com/display/searchnet/Document+attributes
  3. Each document should not be placed in a shared folder but in a subfolder with a name from the database. In this case, it will also be possible to set the folder name part (Facet search) in the search query.

HI.i gone through this.i dont know how to add
[https://docs.groupdocs.com/display/searchnet/Indexing+additional+fields ]

More than one additional field to one document.I need to add Project Name,File Name,Date etc

i referred console app and article link also and needs to add dynamically

image.png (297.2 KB)

@bharathiGK,

You can add an arbitrary number of additional fields to a document during indexing.
It is only necessary to correctly identify the currently indexed document.

index.Events.FileIndexing += (sender, args) =>
{
    string subject;
    if (subjects.TryGetValue(args.DocumentFullPath.ToLowerInvariant(), out subject)) // Getting a subject for the current document
    {
        args.AdditionalFields = new DocumentField[] // Setting additional fields for the current document
        {
            new DocumentField("Subject", subject),
            new DocumentField("ProjectName", projectName),
            new DocumentField("FileName", fileName),
            new DocumentField("Date", date),
            // And so on.
        };
    }
}; 

Let us know if it helps.

Yes.This Method helps me

1 Like

@bharathiGK,

Good to know that.

1 Like