Working with attributes

Text attributes of documents are changed without the need to re-index documents in the search network.

To change document attributes, use the ChangeAttributes method of the Indexer class.

The asynchronous operation flag is available as an option. You can track the completion of the operation by subscribing to the AttributeChangesCompleted event.

The following code example demonstrates changing document attributes on the search network.


Console.WriteLine("Adding attribute: " + attribute);

Indexer indexer = node.Indexer;

AttributeChangeBatch batch = new AttributeChangeBatch();
batch.Add(documentKey, attribute);
ChangeAttributesOptions options = new ChangeAttributesOptions();
indexer.ChangeAttributes(batch, options);

To get all the attributes of a document, use the GetAttributes method of the Indexer class. You must pass the document key as a parameter.

The following code example demonstrates retrieving document attributes from the search network.


Searcher searcher = node.Searcher;
Indexer indexer = node.Indexer;

int[] shardIndices = node.GetShardIndices();
for (int i = 0; i < shardIndices.Length; i++)
    int shardIndex = shardIndices[i];
    NetworkDocumentInfo[] infos = searcher.GetIndexedDocuments(shardIndex);
    for (int j = 0; j < infos.Length; j++)
        NetworkDocumentInfo info = infos[j];
        int nodeIndex = node.GetNodeIndex(info.ShardIndex);
        Console.WriteLine(nodeIndex + ": " + info.ShardIndex + ": " +
            HasErrors(info) + ": " + info.DocumentInfo.FilePath);
        string[] attributes = indexer.GetAttributes(info.DocumentInfo.FilePath);
        for (int k = 0; k < attributes.Length; k++)
            Console.WriteLine("\t\t" + attributes[k]);

More information about working with text attributes of documents in the article Document attributes.

More resources

GitHub examples

You may easily run the code from documentation articles and see the features in action in our GitHub examples:

Free online document search App

Along with full featured .NET library we provide simple, but powerful free Apps.

You are welcome to search over your PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX and more with our free online Free Online Document Search App.