I'm struggling with my custom field added to the external index. I've added a new field as an int.
using System;
using Examine;
using Examine.Providers;
using Umbraco.Core;
using Umbraco.Core.Composing;
namespace MyApp.Composing
{
public class ExamineComponent : IComponent
{
private readonly IExamineManager _examineManager;
public ExamineComponent(IExamineManager examineManager)
{
this._examineManager = examineManager;
}
public void Initialize()
{
var index = this.GetIndex();
CustomiseIndex(index);
index.TransformingIndexValues += this.IndexProviderSetIsDeceased;
}
public void Terminate()
{
var index = this.GetIndex();
index.TransformingIndexValues -= this.IndexProviderSetIsDeceased;
}
private BaseIndexProvider GetIndex()
{
if (!this._examineManager.TryGetIndex(Constants.UmbracoIndexes.ExternalIndexName, out var index))
{
throw new InvalidOperationException(
$"No index found by name {Constants.UmbracoIndexes.ExternalIndexName}");
}
if (!(index is BaseIndexProvider indexProvider))
{
throw new InvalidOperationException("Could not cast");
}
return indexProvider;
}
private static void CustomiseIndex(BaseIndexProvider index)
{
index.FieldDefinitionCollection.TryAdd(new FieldDefinition("isDeceasedFlag", FieldDefinitionTypes.Integer));
}
private void IndexProviderSetIsDeceased(object sender, IndexingItemEventArgs e)
{
var isDeceased = e.ValueSet.GetValue("isDeceased") as int?;
if (isDeceased.HasValue)
{
e.ValueSet.Add("isDeceasedFlag", isDeceased.Value == 1 ? 1 : 0);
}
}
}
}
However I keep getting this error at startup sometimes:
[InvalidOperationException: Could not perform a range query on the field isDeceasedFlag, it's value type is Examine.LuceneEngine.Indexing.FullTextType]
Examine.LuceneEngine.Search.<>c__DisplayClass12_0`1.<RangeQueryInternal>b__0() in C:\Users\Shannon\Documents\_Projects\Examine\Examine\src\Examine\LuceneEngine\Search\LuceneSearchQuery.cs:115
Examine.LuceneEngine.Search.LateBoundQuery.get_Wrapped() in C:\Users\Shannon\Documents\_Projects\Examine\Examine\src\Examine\LuceneEngine\Search\LateBoundQuery.cs:13
Examine.LuceneEngine.Search.LateBoundQuery.ExtractTerms(ISet`1 terms) in C:\Users\Shannon\Documents\_Projects\Examine\Examine\src\Examine\LuceneEngine\Search\LateBoundQuery.cs:37
Lucene.Net.Search.BooleanQuery.ExtractTerms(ISet`1 terms) in d:\Lucene.Net\FullRepo\trunk\src\core\Search\BooleanQuery.cs:504
Examine.LuceneEngine.LuceneSearchResults.DoSearch(Query query, IEnumerable`1 sortField, Int32 maxResults) in C:\Users\Shannon\Documents\_Projects\Examine\Examine\src\Examine\LuceneEngine\LuceneSearchResults.cs:60
Examine.LuceneEngine.Search.LuceneSearchQuery.Search(Int32 maxResults) in C:\Users\Shannon\Documents\_Projects\Examine\Examine\src\Examine\LuceneEngine\Search\LuceneSearchQuery.cs:159
Examine.LuceneEngine.Search.LuceneBooleanOperation.Execute(Int32 maxResults) in C:\Users\Shannon\Documents\_Projects\Examine\Examine\src\Examine\LuceneEngine\Search\LuceneBooleanOperation.cs:46
MyApp.Services.BaseSearchService`1.PagedResults(Int32 page, Int32 pageSize, IQueryExecutor executeQuery) in C:\dev\mfpa\MFPA\MFPA\Services\SearchService.cs:276
I could post my whole search code, but trust me it works (later). The crucial part is:
I may have found the answer to my own issue. I'll post it now and remove it later if the problem reoccurs.
I didn't post my entire code before to keep the post concise. There are in face other TransformingIndexValues event handlers. The culprit being:
private void IndexProviderSetOnlyVisible(object sender, IndexingItemEventArgs e)
{
var hide = e.ValueSet.GetValue(Constants.Conventions.Content.NaviHide) as int?;
if (hide == 1)
{
e.Cancel = true;
}
}
This was my attempt to remove nodes from the index which should be hidden. I'm not clear why this logic is flawed, but I suspect it cancels more than the index of an individual node index.
I'm replacing that with specifying the value in the query
Examine field definition problems
I'm struggling with my custom field added to the external index. I've added a new field as an int.
However I keep getting this error at startup sometimes:
I could post my whole search code, but trust me it works (later). The crucial part is:
However when I re-publish the nodes in question, and reboot the app, then we're all good again.
There's nothing relevant that I can see in the error log on boots which result in this error.
Any help or ideas are appreciate.
I may have found the answer to my own issue. I'll post it now and remove it later if the problem reoccurs.
I didn't post my entire code before to keep the post concise. There are in face other
TransformingIndexValues
event handlers. The culprit being:This was my attempt to remove nodes from the index which should be hidden. I'm not clear why this logic is flawed, but I suspect it cancels more than the index of an individual node index.
I'm replacing that with specifying the value in the query
is working on a reply...