Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

As you can see we added AddComputedIndexField to show how to add custom fields to the index, that runs c# code to generate the values. Lets focus on the computedField DynamicMetadata. With this one we can extract value for a specific metafield. Which metafield, is defined by the attribute metafieldGuid.

Her is an example of the data in solr:

...

When adding a custom search index and be able to do dynamic search from the website. This requires that all the assets are synchronized into Sitecore. You can read about how to do a full synchronization here: DFS 11.0 - Synchronization.

If you want to trigger automatically rebuild of the new index, when the synchronization is done, then look at the pipeline DFS.BatchSync in App_Config\Include\damforsitecore\DFS.Pipelines.config. Change the indexName to your new index.

...

Example of searching

Here is an example of how to search the index.
Give me all entries where assetId is not empty, no crop assets, only assets of assettype 4 (images) and last we freetext search the title.

Code Block
languagec#
var index = ContentSearchManager.GetIndex("dfs_contentsearch_master_index");
using (var searchContext = index.CreateSearchContext(SearchSecurityOptions.DisableSecurityCheck))
{
    var queryable = searchContext.GetQueryable<AssetResultItem>().Where(q => q.AssetId != string.Empty);
    queryable = queryable.Where(q => q.Derivedfrom == "0");
    queryable = queryable.Where(q => q.Assettype == "4");
    queryable = queryable.Where(q => q.Title.Contains(freeText));

    var res = queryable.GetResults();

    foreach (var searchResult in res)
    {
        renderList.assets.Add(new asset()
        {
            htmlTag = searchResult.Document.Thumbhtmltag,
            title = searchResult.Document.Title
        });
    }
}

Example of a website using the search.

...

You can download all the configuration and c# files here:

...