Versions Compared

Key

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

...

Code Block
languagexml
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:search="http://www.sitecore.net/xmlconfig/search/">
  <sitecore search:require="solr">
    <contentSearch>
      <indexConfigurations>
        <!-- If no configuration is specified for an index, it uses the default configuration. The configurations are not merged if the index also has a
             configuration. The system uses either the default configuration or the index configuration. -->
        <DFS.ContentSearch.Solr.IndexConfiguration ref="contentSearch/indexConfigurations/defaultSolrIndexConfiguration">
          <documentOptions type="Sitecore.ContentSearch.SolrProvider.SolrDocumentBuilderOptions, Sitecore.ContentSearch.SolrProvider">
            <indexAllFields>true</indexAllFields>
            
			<include hint="list:AddIncludedTemplate">
              <DFSRootTemplateId>{316978B1-1C41-4F4F-82D5-82863665EDE6}</DFSRootTemplateId>
              <AssetsSiloTemplateId>{4133449F-6EC1-4D10-A930-3EC828650FA6}</AssetsSiloTemplateId>
              <AssetTemplateId>{2D63B0B3-89AA-4A87-9A32-D822C71B5BD8}</AssetTemplateId>      
              <MappedEntityTemplateId>{B8879FB6-ADE9-4971-B580-CF0073FC182A}</MappedEntityTemplateId>
              <DigizuiteEntityTemplateId>{801EC0D4-6D99-4609-B042-96388D314BFD}</DigizuiteEntityTemplateId> 
            </include>
			
            <fields hint="raw:AddComputedIndexField">
              <field fieldName="mfTitle" metafieldGuid="5eb3eefc-a043-410f-89b0-29ed3ef37078" returnType="string">DFS.Client.Services.ContentSearch.ComputedFields.DynamicMetadata, DFS.Client.Services</field>   			  
			  <field fieldName="mfPublishTo" metafieldGuid="74a5a102-a310-4bb7-9e84-0b14c36436b2" returnType="stringCollection">DFS.Client.Services.ContentSearch.ComputedFields.DynamicMetadata, DFS.Client.Services</field>	
			  <field fieldName="thumbHtmlTag" returnType="string">DFS.Client.Services.ContentSearch.ComputedFields.ThumbHtmlTag, DFS.Client.Services</field>   
			  <field fieldName="derivedFrom" returnType="string">DFS.Client.Services.ContentSearch.ComputedFields.DerivedFrom, DFS.Client.Services</field>   			  
            </fields>				
          </documentOptions> 
        </DFS.ContentSearch.Solr.IndexConfiguration>
      </indexConfigurations>
    </contentSearch>
  </sitecore>
</configuration>

We have added some As you can see we added AddComputedIndexField to show how to add new custom fields to the index, that runs som c# code to generate the values. Lets focus on the computedField DynamicMetadata. With this one we can extract value for the fields.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 code examples configuration and c# files here:

View file
nameCustom index files.zip

...