I've news stories that are tagged with news categories e.g. sport, film, local. The user can tag a news item with multiple categories. I'm using a mutlinode treepicker to select tags for each article.
What I now need to do is find a way to create a dropdown list of categories that have been used by a news story to allow for filtering. Is this possible with Examine and can anyone give me some pointers? I'm using V8.
If for example I have a list of category doctypes :
Sport
Local
Weather
Film
and I have 2 news articles, one tagged with Sport and the other with Local and Weather, the dropdown list would only display Sport, Local, Weather. Not Film.
It might be better to use Relationships for this instead of Examine.
You'd have to hook into the save/publish event and add a relationship between the news article node and the picked categories nodes.
Then you could search for all relationships of this type to know which categories to display.
If you do this though, remember to hook into the delete/unpublish events to remove the relationships for the given nodes :-)
You could also try nuPickers https://our.umbraco.com/packages/backoffice-extensions/nupickers/. It is a collection of pickers that can be powered by different data sources. One of the options is the Lucene DropDown Picker. I use the Enum pickers and DotNet pickers a lot, but have not personally used the Lucene pickers.
The only thing negative I can think to say about this is that it hasn't yet been ported to Umbraco 8 yet.
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Services.Implement;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using System.Linq;
using Umbraco.Core.Events;
using Umbraco.Core.Models.PublishedContent;
using System.Collections.Generic;
namespace ProjectX.Core.Components
{
class CheckTagsOnArticlesComponent : IComponent
{
private readonly IRelationService _relationService;
// register our component with Umbraco using a Composer
public CheckTagsOnArticlesComponent(IRelationService relationService)
{
_relationService = relationService;
}
public void Initialize()
{
// subscribe to content service published event
ContentService.Published += ContentService_Published;
}
// initialize: runs once when Umbraco starts
private void ContentService_Published(IContentService sender, ContentPublishedEventArgs e)
{
foreach (var node in e.PublishedEntities)
{
if (node.ContentType.Alias.ToLowerInvariant() == "stories")
{
// Get the Id of the node that was published
var id = node.Id;
if (node.HasProperty("theme"))
{
}
var relationType = _relationService.GetRelationTypeByAlias("relateStoryToTheme");
if (relationType == null) return;
foreach (var entity in e.PublishedEntities.Where(x => x.Id != node.Id))
{
if (!_relationService.AreRelated(node.Id, entity.Id))
{
_relationService.Relate(node.Id, entity.Id, relationType);
}
}
}
}
}
// terminate: runs once when Umbraco stops
public void Terminate()
{
// do something when Umbraco terminates
}
}
}
So, I've spent most of the afternoon working on this and I think it's getting there, but I'm up against it with hours so if anyone could point me in a more complete solution, that would really be appreciated.
Just now, it hits the if node alias is stories which is a start. but then I need to create the relationship between the story and the multinode tree picker values which are with an alias of theme.
Just now node.HasProperty("theme") returns true then bombs out at var relationType
Create a dropdown list from Examine
Hi,
I've news stories that are tagged with news categories e.g. sport, film, local. The user can tag a news item with multiple categories. I'm using a mutlinode treepicker to select tags for each article.
What I now need to do is find a way to create a dropdown list of categories that have been used by a news story to allow for filtering. Is this possible with Examine and can anyone give me some pointers? I'm using V8.
If for example I have a list of category doctypes :
and I have 2 news articles, one tagged with Sport and the other with Local and Weather, the dropdown list would only display Sport, Local, Weather. Not Film.
Does this make sense?
Thanks, O.
It might be better to use Relationships for this instead of Examine. You'd have to hook into the save/publish event and add a relationship between the news article node and the picked categories nodes.
Then you could search for all relationships of this type to know which categories to display.
If you do this though, remember to hook into the delete/unpublish events to remove the relationships for the given nodes :-)
Ok, this sounds interesting and sounds like an option.
Is this what you are referring to? https://our.umbraco.com/Documentation/Reference/Management/Models/RelationType
Yeah that's the one :-)
You could also try nuPickers https://our.umbraco.com/packages/backoffice-extensions/nupickers/. It is a collection of pickers that can be powered by different data sources. One of the options is the
Lucene DropDown Picker
. I use the Enum pickers and DotNet pickers a lot, but have not personally used the Lucene pickers.The only thing negative I can think to say about this is that it hasn't yet been ported to Umbraco 8 yet.
Not having it on V8 is a show stopper for me. I'm working on the project right now so need to working.
I've started going down the route of creating relationships. I've got my publish function setup so will work on the rest this afternoon :)
So, I've spent most of the afternoon working on this and I think it's getting there, but I'm up against it with hours so if anyone could point me in a more complete solution, that would really be appreciated.
Just now, it hits the
if node alias is stories
which is a start. but then I need to create the relationship between the story and the multinode tree picker values which are with an alias oftheme
.Just now
node.HasProperty("theme")
returns true then bombs out atvar relationType
O.
Soz for briefness, but if you wanna BYO, see if this helps as well. 🙂
http://blog.aabech.no/archive/building-a-spell-checker-for-search-in-umbraco/
is working on a reply...