I have a umbraco doctype with a field that is of type Umbraco.Tags.
Using examine to search the field like this:
var searchEngine = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
var searchCriteria = searchEngine.CreateSearchCriteria(BooleanOperation.Or);
var query = searchCriteria.Field("title", searchTerm)
.Or().Field("topicTags", searchTerm).Compile();
var results = searchEngine.Search(query);
I know for a fact that the value is inside topicTags, but it result is 0...
yes, it is indexed, the reason why I was getting 0 was the tags are stored like this: tag1,tag2,tag3. With no spaces so tag1,tag2,tag3 would result in a hit, but tag1 wouldn't.
The solution was to hook in to the umbraco publish event and change the way that field is indexed. Solution below:
public class ExamineEvents : ApplicationStartupHandler
{
public ExamineEvents()
{
ExamineManager.Instance.IndexProviderCollection["ExternalIndexer"].GatheringNodeData +=
ExamineEvents_GatheringNodeData;
}
private void ExamineEvents_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
{
if (e.IndexType != IndexTypes.Content) return;
// Node picker values are stored as csv which will not be indexed properly
// We need to write the values back into the index without commas so they are indexed correctly
var fields = e.Fields;
var searchableFields = new Dictionary<string, string>();
foreach (var field in fields)
{
switch (field.Key)
{
case "topicTags":
var searchableFieldKey = "topicTagsIndexed";
var searchableFieldValue = field.Value.Replace(',', ' ');
if (!string.IsNullOrEmpty(searchableFieldValue))
{
searchableFields.Add(searchableFieldKey, searchableFieldValue);
}
break;
}
}
foreach (var fld in searchableFields)
{
e.Fields.Add(fld.Key, fld.Value);
}
}
Then when you create your search query you search in the field topicTagsIndexed
Using Examine to search Umbraco.Tags
Hey guys,
I have a umbraco doctype with a field that is of type Umbraco.Tags.
Using examine to search the field like this:
I know for a fact that the value is inside topicTags, but it result is 0...
Any ideas?
Hi Ayo,
Are you sure that your 'topicTags' property are indexed ?
Try to use something like ExamineManager for checking data returned form the Examine Index.
http://our.umbraco.org/documentation/Reference/Searching/Examine/examine-manager
Thanks, Alex
yes, it is indexed, the reason why I was getting 0 was the tags are stored like this: tag1,tag2,tag3. With no spaces so tag1,tag2,tag3 would result in a hit, but tag1 wouldn't.
The solution was to hook in to the umbraco publish event and change the way that field is indexed. Solution below:
Then when you create your search query you search in the field topicTagsIndexed
Hope this helps someone else.
is working on a reply...