The issue is that the contentTags field stores data in a comma seperated list, and it won't return nodes when there is more than one item in that field.
e.g.
I add 'testasdf123' to the field and do a save and publish. When I search for 'testasdf123' the node is returned. However, if I add another tag, so that the field is saved in umbraco as 'testasdf123,SEO' then the node IS NOT returned.
Note that this property is a custom data type that is a usercontrol using the umbraco usercontrol wrapper and the Database datatype is Ntext (in case that makes a difference).
There is a known issue with comma seperated values and examine/lucene. The work around we use is to hook into Examine's GatheringNodeData event and split the csv by spaces rather than with commas:
using System;
using System.Text;
using System.Xml.Linq;
using Examine;
using umbraco.BusinessLogic;
using umbraco.MacroEngines;
using umbraco.presentation.nodeFactory;
using Umbraco_Site_Extensions.automation;
using UmbracoExamine;
namespace Umbraco_Site_Extensions.examineExtensions
{
///
/// handle any lucene data injection here
///
public class ExamineEvents:ApplicationBase
{
public ExamineEvents()
{
ExamineManager.Instance.IndexProviderCollection[INDEX_NAME].GatheringNodeData += ExamineEvents_GatheringNodeData;
}
void ExamineEvents_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
{
if (e.IndexType == IndexTypes.Content)
{
var node = new Node(e.NodeId);
InjectNewsCategoriesWithOutComma(e, node);
}
}
///
/// cannot do searching with comma in values properly
///
///
///
private void InjectNewsCategoriesWithOutComma(IndexingNodeDataEventArgs e, Node node)
{
if (node.NodeTypeAlias == Constants.NewsItemTypeAlias &&
node.GetPropertyValue(Constants.NewsCategoryFieldAlias) != string.Empty)
{
e.Fields.Add( Constants.NewsCategoryFieldAlias +"Searchable", node.GetPropertyValue(Constants.NewsCategoryFieldAlias).Replace(","," "));
}
}
}
}
You'll also need to add the new field into the IndexUserFields element as well but otherwise you should be good to go
Searching csv fields using examine
Hi,
I am using examine for searching some custom fields in umbraco. I have added the custom fields the ExamineIndex.config like so
<IndexUserFields>
<add Name="contentTags" />
...
And am doing a basic search like this:
IEnumerable<SearchResult> results = ExamineManager.Instance.Search(cleanedSearchTerm, true);
The issue is that the contentTags field stores data in a comma seperated list, and it won't return nodes when there is more than one item in that field.
e.g.
I add 'testasdf123' to the field and do a save and publish. When I search for 'testasdf123' the node is returned. However, if I add another tag, so that the field is saved in umbraco as 'testasdf123,SEO' then the node IS NOT returned.
Note that this property is a custom data type that is a usercontrol using the umbraco usercontrol wrapper and the Database datatype is Ntext (in case that makes a difference).
Any clues?
There is a known issue with comma seperated values and examine/lucene. The work around we use is to hook into Examine's GatheringNodeData event and split the csv by spaces rather than with commas:
You'll also need to add the new field into the IndexUserFields element as well but otherwise you should be good to go
Hey, I eventually found this in another blog. Thanks anyway!
Couple small notes here:
is working on a reply...