[SOLVED] Search price range with Examine
# help-with-umbraco
b
Hi, I added an extra field 'estatePrice' to my index definitions.
Copy code
public class ConfigureIndexOptions : IConfigureNamedOptions<LuceneDirectoryIndexOptions>
{
    public void Configure(string name, LuceneDirectoryIndexOptions options)
    {
        ...
        options.FieldDefinitions.AddOrUpdate(new FieldDefinition("estatePrice", FieldDefinitionTypes.Long));
        ...
    }
}
This field is filled with a value in UmbracoContextIndex_TransformingIndexValues
Copy code
private void UmbracoContextIndex_TransformingIndexValues(object sender, IndexingItemEventArgs e)
{
  ...
  dictionary.Add("estatePrice", new List<object> { decimal.ToInt64(estateComposition.Price) });
  ...
}
Everything looks fine, my values are present in the indexes. But when I try to search this field with a range query
Copy code
queryBuilder.And().RangeQuery<float>(new[] { "estatePrice" }, intMin, intMax);
I keep getting the error:
Copy code
System.InvalidOperationException: 'Could not perform a range query on the field estatePrice, it's value type is Examine.Lucene.Indexing.FullTextType'
What am I missing? Or is there another possible way to search a range with Examine? Thanks for any help. https://cdn.discordapp.com/attachments/1162356497603366952/1162356497775337513/image.png?ex=653ba3d8&is=65292ed8&hm=c357e4e407918461dbdc3a0830e1ada3a8dd0537ec2f0ca3840c665ece5c5318& https://cdn.discordapp.com/attachments/1162356497603366952/1162356498022793287/image.png?ex=653ba3d8&is=65292ed8&hm=b55c5ccb2ed8347c54eededa73a2e84634a57a59ccc4ec44eb6fd887e2c892f0&
d
Hi there! Just to be sure: can you verify that the code from your first snippet is actually executed?
m
did you add a composer to add you luceneoptions config updates?
Copy code
public class ExamineIndexOptionsComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
    {
        // Custom Examine configuration
        builder.Services.ConfigureOptions<ConfigureExamineIndexOptions>();
    }
}
and also rebuild your indexes?
b
I actually have 2 index definitions.
Copy code
public void Configure(string name, LuceneDirectoryIndexOptions options)
{
    if (name != Constants.UmbracoIndexes.ExternalIndexName) return;

    options.FieldDefinitions.AddOrUpdate(new FieldDefinition("estatePrice", FieldDefinitionTypes.Long));
    options.FieldDefinitions.AddOrUpdate(new FieldDefinition("estateImportCreateDateTime", FieldDefinitionTypes.Long));
}
Both are longs, the other field is used for sorting and does not give errors.
Copy code
queryBuilder.OrderByDescending(new SortableField("estateImportCreateDateTime", SortType.Long));
So I can assume that the code executed.
Okay, so I was missing this Compose method 😅 . I was certain that the code was executed because the fields were present in the index 🧐 . Thanks for the help both of you!
5 Views