Hi everyone,
I'm looking for some help.
I've got a requirement to display a dropdown list of the types of Document Types / Pages that are available to filter by. Just now for example I have a list with
Article
Video
Podcast
And that works fine, it pulls back a Distinct list of types, however, I have a Document Type called Generic and on that docType I have a content picker which allows the user to select a Content Label, this should then override the Document Type and display on the dropdown list
So instead of
Article
Video
Podcast
Generic
It should show
Article
Video
Podcast
Interview
If interview was the label selected on the Generic Document Type.
Here is my code so far:
public ActionResult GetDistinctContentTypesForTopics(string topic)
{
var searcher = ExamineManager.Instance.SearchProviderCollection["ContentHubSearcher"];
ISearchCriteria searchCriteria = searcher.CreateSearchCriteria(IndexTypes.Content);
IBooleanOperation query = searchCriteria.GroupedOr(new string[] { "pagePostTags" }, topic);
var queryResults = searcher.Search(query.Compile());
IEnumerable<string> contentLabel = queryResults.Select(x => x["contentLabel"]).Distinct().ToList();
List<string> contentLabelText = new List<string>();
// This gets the label if one is present, I should maybe check if it's of Type Generic too.
if (contentLabel != null || contentLabel.Any())
{
foreach (var label in contentLabel)
{
var labelGuid = Umbraco.TypedContent(label);
if (labelGuid != null)
{
if(labelGuid.HasValue("labelTitle"))
{
var labelText = labelGuid.GetPropertyValue<string>("labelTitle");
contentLabelText.Add(labelText);
}
}
}
}
// If nodeTypeAlias has Content Label, use that instead of nodeAlias
var allSearchResults = queryResults.Select(x => x["nodeTypeAlias"]).Distinct().ToList();
List<string> allResults = contentLabelText.Union(allSearchResults).Distinct().ToList();
return PartialView("Topics/ContentTypesDropdown", allResults);
}
I tried to do a union of the two lists that I have but that doesn't work because I'm guessing I'm still pulling back the Generic Document Type.
If anyone has some time to help me with this it would be amazing.
It's Umbraco 7 project.
What about if you modify the indexing process to put values in a specific field rather than searching node type alias.
You could put a custom field called "DocumentType" and in that store the node type for your normal docs, but for the generic doc type store the tagged label instead.
Then when you get your results back you can get the distinct values from that instead.
Examine query that adds results to a list
Hi everyone, I'm looking for some help. I've got a requirement to display a dropdown list of the types of Document Types / Pages that are available to filter by. Just now for example I have a list with
And that works fine, it pulls back a Distinct list of types, however, I have a Document Type called Generic and on that docType I have a content picker which allows the user to select a Content Label, this should then override the Document Type and display on the dropdown list
So instead of
It should show
If interview was the label selected on the Generic Document Type.
Here is my code so far:
I tried to do a union of the two lists that I have but that doesn't work because I'm guessing I'm still pulling back the Generic Document Type.
If anyone has some time to help me with this it would be amazing. It's Umbraco 7 project.
Thanks, O.
Hey Owain :-D
What about if you modify the indexing process to put values in a specific field rather than searching node type alias.
You could put a custom field called "DocumentType" and in that store the node type for your normal docs, but for the generic doc type store the tagged label instead.
Then when you get your results back you can get the distinct values from that instead.
Nik
Hey, Well, funny you should say that. In my index I have:
nodeTypeAlias: genericContent
andcontentLabel: 8633135048b64d8a85cda7357819f28d
So really, I should swap out the genericContent nodeTypeAlias and convert the guid to the label?
O.
is working on a reply...