Sample User Profile Content search

Current version: 8.2

Searching for profiles is done by using the Sitecore ContentSearch API.

The following is an example of how to search for a user by address:

RequestResponse

var index = ContentSearchManager.GetIndex("commerce_userprofiles_index_master");

using (var context = index.CreateSearchContext())
{
var query = context.GetQueryable<CommerceProfileSearchResult>()
       	.Where(item => item.Content.Contains("123 Jane Street"));

       var result = query.GetResults();


       var indexItem = result.Hits.ElementAt(0);
}

The Content property of the CommerceProfileSearchResult class is used to perform the address search. All information for all associated addresses is added to the _content index field.

The following is an example of how to search for a specific user by email address:

RequestResponse

var index = ContentSearchManager.GetIndex("commerce_userprofiles_index_master");

using (var context = index.CreateSearchContext())
{
var query = context.GetQueryable<CommerceProfileSearchResult>()
.Where(item => item["email_address"] == "[email protected]");

       var result = query.GetResults();

       var indexItem = result.Hits.ElementAt(0);
       var email = indexItem.Document["email_address"];
}

Do you have some feedback for us?

If you have suggestions for improving this article,