Olti
01/31/2025, 11:40 AMpath: -1,1600,1603,1611,2227
__IndexType: pdf
nodeName: Marketing Document
fileTextContent: "This document contains marketing strategies..."
- 1603 is my media root folder (selected by the user).
- 2227 is the actual PDF file inside /HQM/blog1/.
Lucene Query That Works in Examine Management
If I manually search in Examine Management with:
fileTextContent:marketing~2 OR nodeName:marketing~2
I get results.
Lucene Query That My Code Generates (Fails)
Hereβs what my code generates:
Lucene Query: { Category: pdf, LuceneQuery: +(fileTextContent:marketing~2 nodeName:marketing~2) +path:1603* }
This returns zero results β, even though 1603* should match -1,1600,1603,1611,2227.Olti
01/31/2025, 11:40 AMJemayn
01/31/2025, 11:43 AM*1603*
should match, or -1,1600,1603*
should.
I haven't worked with paths in the PDF index, but it will depend on how the values are indexed. You can't visually see a difference in the backoffice viewer between values indexed as:
"1,2,3,4"
and [1,2,3,4]
But the way Examine handles a "multivalue field" and a single value field containing a string of multiple comma separated values are very differentOlti
01/31/2025, 11:55 AMJemayn
01/31/2025, 1:27 PM"-1,1600,1603,1611,2227"
lucene will treat it as "11600160316112227"
which leads to issues when filtering by one of the node ids.
My guess is that is what you are running into here. So indexing the path in a TransformingIndexValues event may fix your issueOlti
01/31/2025, 1:48 PMOlti
01/31/2025, 1:49 PMusing Examine;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Notifications;
namespace HunzikerIntranet.HQM.Umbraco.Infrastructure.Examine
{
public class PDFIndexPathTransformer : INotificationHandler<UmbracoApplicationStartedNotification>
{
private readonly IExamineManager _examineManager;
private readonly ILogger<PDFIndexPathTransformer> _logger;
public PDFIndexPathTransformer(IExamineManager examineManager, ILogger<PDFIndexPathTransformer> logger)
{
_examineManager = examineManager;
_logger = logger;
}
public void Handle(UmbracoApplicationStartedNotification notification)
{
if (!_examineManager.TryGetIndex("PDFIndex", out var pdfIndex))
{
_logger.LogError("PDFIndex not found in Examine.");
return;
}
pdfIndex.TransformingIndexValues += IndexOnTransformingIndexValues;
}
private void IndexOnTransformingIndexValues(object? sender, IndexingItemEventArgs e)
{
if (!e.ValueSet.Values.ContainsKey("path")) return;
var rawPath = e.ValueSet.Values["path"].FirstOrDefault()?.ToString();
if (string.IsNullOrEmpty(rawPath)) return;
var searchablePath = rawPath.Replace(",", " ");
var indexFields = e.ValueSet.Values.ToDictionary(x => x.Key, x => x.Value.ToList());
indexFields["searchablePath"] = new List<object> { searchablePath };
e.SetValues(indexFields.ToDictionary(x => x.Key, x => (IEnumerable<object>)x.Value));
}
}
}
Jemayn
01/31/2025, 1:51 PMOlti
01/31/2025, 1:55 PMOlti
01/31/2025, 1:55 PMJemayn
01/31/2025, 2:16 PM