I was wondering if anyone has successfully managed to search the External index for a UDI?
I've got a part of my site where a user can make selections which triggers node ids to be sent to the server. I need to be able to search these ids in Examine. These ids are dictated by a Multinode Treepicker which stores the data as UDIs.
Since I have the ids I want to search on, I could just convert them to UDIs, however whenever I search all or part of a UDI it returns no results.
Anyone done something similar?
I'm aware of NuPickers but I wanted to try avoid using any packages if possible.
Problem is, that the UDI is not (by default) indexed in Examine. In stead, the guid (which the UDI is based upon) is. The guid is indexed in the column Key.
So you could convert your UDI to a Guid, and find what you need.
Ie. umb://document/4fed18d8c5e34d5e88cfff3a5b457bf2 would need to be transformed into 4fed18d8-c5e3-4d5e-88cf-ff3a5b457bf2.
So I hit the same issue and resolved it by adding an examine indexer that added a custom field for the UDI
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ExamineManager.Instance.IndexProviderCollection["NewsIndexer"]
.GatheringNodeData += OnGatheringNodeData;
}
private void OnGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
{
var node = new Node(e.NodeId);
e.Fields.Add(CmsConstants.ExamineConstants.CATEGORY_FILTER, BuildFilter(node, "categories"));
}
public string BuildFilter(Node node, string property)
{
var values = node.Properties[property].ToString();
var ids = new StringBuilder();
foreach (var id in values.Split(','))
{
if (ids.Length > 0)
{
ids.Append(" ");
}
ids.Append(id.Replace("umb://document/", ""));
}
return ids.ToString();
}
Then when searching the index by the document, where I had the primary key of the document and not the UDI I used the umbraco helper to get the page by id, something like this (_umbracoHelper is of type UmbracoHelper):
I have the same issue and posted another forum question on this. I looks like the umb syntax (containing a colon (:) causes a lucene syntax error because the colon is used as the key/value separator in the raw query.
In my case, I am searching a members index set and searching against a value of a content picker. That content picker is returning a umb string as I can see it when I search all by removing the search criteria.
In the end, I had to build a raw query and then add wildcards before the key value and change my search value from a umb to a guid where I stripped out the "-" characters.
Here is my code for this:
var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalMemberSearcher"];
var criteria = searcher.CreateSearchCriteria();
var contentTypeFilter = string.Format("__IndexType:{0}", UmbracoExamine.IndexTypes.Member);
var searchKey = "advisor";
//var searchValue = Udi.Create(Constants.UdiEntityType.Document, currentAdvisor.GetKey()).ToString(); // This does not work as the umb colon causes a lucene sytax error
var searchValue = currentAdvisor.GetKey().ToString().Replace("-","");
var query = new StringBuilder();
query.AppendFormat("+{0} ", contentTypeFilter);
query.AppendFormat("+({0}:*{1}*)", searchKey, searchValue);
var searchResults = searcher.Search(criteria.RawQuery(query.ToString()));
Also, importantly you need to addenableLeadingWildcard="true" to your searcher config in examineSettings.config. I understand this is not performant, but what to do...
Searching Examine for UDI
Hi All
I was wondering if anyone has successfully managed to search the External index for a UDI?
I've got a part of my site where a user can make selections which triggers node ids to be sent to the server. I need to be able to search these ids in Examine. These ids are dictated by a Multinode Treepicker which stores the data as UDIs.
Since I have the ids I want to search on, I could just convert them to UDIs, however whenever I search all or part of a UDI it returns no results.
Anyone done something similar?
I'm aware of NuPickers but I wanted to try avoid using any packages if possible.
Hi Alex
Problem is, that the UDI is not (by default) indexed in Examine. In stead, the guid (which the UDI is based upon) is. The guid is indexed in the column
Key
.So you could convert your UDI to a Guid, and find what you need.
Ie.
umb://document/4fed18d8c5e34d5e88cfff3a5b457bf2
would need to be transformed into4fed18d8-c5e3-4d5e-88cf-ff3a5b457bf2
.Hi,
So I hit the same issue and resolved it by adding an examine indexer that added a custom field for the UDI
Then when searching the index by the document, where I had the primary key of the document and not the UDI I used the umbraco helper to get the page by id, something like this (_umbracoHelper is of type UmbracoHelper):
Then the value to use in examine search becomes:
I have the same issue and posted another forum question on this. I looks like the umb syntax (containing a colon (:) causes a lucene syntax error because the colon is used as the key/value separator in the raw query.
In my case, I am searching a members index set and searching against a value of a content picker. That content picker is returning a umb string as I can see it when I search all by removing the search criteria.
In the end, I had to build a raw query and then add wildcards before the key value and change my search value from a umb to a guid where I stripped out the "-" characters.
Here is my code for this:
Also, importantly you need to add
enableLeadingWildcard="true"
to your searcher config in examineSettings.config. I understand this is not performant, but what to do...is working on a reply...