Craig100
09/02/2023, 1:23 PMhuwred
09/02/2023, 2:08 PMcsharp
var today = DateTime.Now;
long min = today.Ticks;
long max = today.Ticks;
query ??= "7d";
switch (query)
{
case "30m" :
min = today.AddMinutes(-30).Ticks;
break;
case "60m" :
min = today.AddHours(-1).Ticks;
break;
case "1d" :
min = today.AddDays(-1).Ticks;
break;
case "7d" :
min = today.AddDays(-7).Ticks;
break;
case "1m" :
min = today.AddMonths(-1).Ticks;
break;
case "1y" :
min = today.AddYears(-1).Ticks;
break;
}
int pageIndex = page - 1;
if(pageIndex < 0) {pageIndex = 0;}
int pageSize = CurrentPage.Value<int>("intPageSize");
if (_examineManager.TryGetIndex("ForumIndex", out var index))
{
var searcher = index.Searcher;
var examineQuery = searcher.CreateQuery(IndexTypes.Content)
.Field("postType", "Topic")
.And().RangeQuery<long>(new string[] { "updated" }, min, max)
.OrderByDescending(new SortableField[] { new SortableField("updateDate") });
results = examineQuery.Execute();
}
Craig100
09/02/2023, 4:56 PMCraig100
09/02/2023, 9:44 PMSystem.InvalidOperationException: Could not perform a range query on the field deceasedDateOfBirth, it's value type is Examine.Lucene.Indexing.FullTextType
at Examine.Lucene.Search.LuceneSearchQuery.<>c__DisplayClass13_0`1.<RangeQueryInternal>b__0()
The code is searchQuery.And().Field("deceasedDateOfBirth", searchDOBTicks);
where "searchDOBTicks" can be ticks or string as I try out different options.......
I'm not trying to do a range query I just want a match with what looks like "02/05/1965 00:00:00" in the Index. I've also tried converting my "1965-05-02" to both "02/05/1965" and "02/05/1965 00:00:00" as well as Ticks but nothing works so far 😦Craig100
09/02/2023, 10:08 PMCraig100
09/02/2023, 10:32 PMD_Inventor
09/03/2023, 6:52 AM"05/06/1934".Explicit()
to actually search for the whole string, rather than the individual components.Craig100
09/03/2023, 8:06 AMnathanwoulfe
09/03/2023, 8:07 AMCraig100
09/03/2023, 8:09 AMhuwred
09/03/2023, 9:15 AMCraig100
09/14/2023, 10:26 AMCraig100
09/15/2023, 5:12 PMif (!searchDOB.IsNullOrWhiteSpace()) {
DateTime searchDOBDT = new DateTime(Int32.Parse(searchDOB.Split("-")[0]), Int32.Parse(searchDOB.Split("-")[1]), Int32.Parse(searchDOB.Split("-")[2]));
searchQuery.And().RangeQuery<DateTime>(new[] {"deceasedDateOfBirth"}, searchDOBDT, searchDOBDT);
}
Which gives the expected error: InvalidOperationException: Could not perform a range query on the field deceasedDateOfBirth, it's value type is Examine.Lucene.Indexing.FullTextType
. So I guess I'll have to workout how to make the date picker save as a DateTime instead of a String, if that's even possible.nathanwoulfe
09/16/2023, 8:12 AMCraig100
09/16/2023, 10:03 AMCraig100
09/16/2023, 10:36 AMpublic class SearchIndexOptions : IConfigureNamedOptions<LuceneDirectoryIndexOptions>
{
public void Configure(string name, LuceneDirectoryIndexOptions options)
{
if (name == "ExternalIndex")
{
options.FieldDefinitions.AddOrUpdate(new FieldDefinition("deceasedDateOfBirth", "Date"));
}
}
public void Configure(LuceneDirectoryIndexOptions options) {
throw new NotImplementedException();
}
}
Craig100
09/16/2023, 10:39 AMsearchQuery.And().RangeQuery<long>(new[] {"deceasedDateOfBirth"}, searchDOBDT.Ticks, searchDOBDT.Ticks);
doesn't help either.Craig100
09/16/2023, 1:35 PMMike Chambers
09/17/2023, 9:28 AM"datetime"
though I'd use..
options.FieldDefinitions.AddOrUpdate(new FieldDefinition("deceasedDateOfBirth", FieldDefinitionTypes.DateTime));
from the examine namespace to avoidMike Chambers
09/17/2023, 9:30 AMvar deceasedDateOfBirth = {DocType}.GetModelPropertyType(_publishedSnapshotAccessor, x => x.deceasedDateOfBirth)!.Alias;
if you are using models builder?Mike Chambers
09/17/2023, 9:30 AMCraig100
09/17/2023, 9:32 AMMike Chambers
09/17/2023, 9:41 AMCraig100
09/17/2023, 9:52 AMpublic class ConfigureIndexOptions : IConfigureNamedOptions<LuceneDirectoryIndexOptions>
{
private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor;
public ConfigureIndexOptions(IPublishedSnapshotAccessor publishedSnapshotAccessor) {
_publishedSnapshotAccessor = publishedSnapshotAccessor;
}
public void Configure(string name, LuceneDirectoryIndexOptions options)
{
if (name == "ExternalIndex") //Breakpoint here not hit
{
var deceasedDateOfBirth = MemorialPage.GetModelPropertyType(_publishedSnapshotAccessor, x => x.DeceasedDateOfBirth)!.Alias;
var deceasedDateOfDeath = MemorialPage.GetModelPropertyType(_publishedSnapshotAccessor, x => x.DeceasedDateOfDeath)!.Alias;
options.FieldDefinitions.AddOrUpdate(new FieldDefinition(deceasedDateOfBirth, FieldDefinitionTypes.DateTime));
options.FieldDefinitions.AddOrUpdate(new FieldDefinition(deceasedDateOfDeath, FieldDefinitionTypes.DateTime));
}
}
public void Configure(LuceneDirectoryIndexOptions options) {
throw new NotImplementedException();
}
}
Mike Chambers
09/17/2023, 9:53 AMCraig100
09/17/2023, 9:55 AMMike Chambers
09/17/2023, 9:56 AMCraig100
09/17/2023, 9:56 AMMike Chambers
09/17/2023, 9:56 AMservices.AddTransient<ConfigureIndexOptions>();
which this is doing.Craig100
09/17/2023, 9:57 AMMike Chambers
09/17/2023, 9:58 AMCraig100
09/17/2023, 9:59 AMSystem.InvalidOperationException: Wasn't possible to a get a valid Snapshot
at Umbraco.Extensions.PublishedSnapshotAccessorExtensions.GetRequiredPublishedSnapshot(IPublishedSnapshotAccessor publishedSnapshotAccessor)
on start upCraig100
09/17/2023, 10:00 AMMike Chambers
09/17/2023, 10:01 AMCraig100
09/17/2023, 10:02 AMMike Chambers
09/17/2023, 10:03 AMCraig100
09/17/2023, 10:04 AMCraig100
09/17/2023, 10:05 AMCraig100
09/17/2023, 10:06 AMpublic class ConfigureIndexOptions : IConfigureNamedOptions<LuceneDirectoryIndexOptions>
{
public void Configure(string name, LuceneDirectoryIndexOptions options)
{
if (name == "ExternalIndex")
{
options.FieldDefinitions.AddOrUpdate(new FieldDefinition("deceasedDateOfBirth", FieldDefinitionTypes.DateTime));
options.FieldDefinitions.AddOrUpdate(new FieldDefinition("deceasedDateOfDeath", FieldDefinitionTypes.DateTime));
}
}
public void Configure(LuceneDirectoryIndexOptions options) {
throw new NotImplementedException();
}
}
public class IndexOptionsComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
// Custom Examine configuration
builder.Services.ConfigureOptions<ConfigureIndexOptions>();
}
}
Craig100
09/17/2023, 10:07 AMMike Chambers
09/17/2023, 10:07 AMConstants.UmbracoIndexes.ExternalIndexName
Craig100
09/17/2023, 10:08 AMCraig100
09/17/2023, 10:08 AMMike Chambers
09/17/2023, 10:09 AMExternalLuceneIndex
vs ExternalElaticIndex
😉Craig100
09/17/2023, 10:09 AMMike Chambers
09/17/2023, 10:10 AM