Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Peculiar exception on long range query - field type claims to be FullTextType when it is explicitly set to Long #208

Open
lindeberg opened this issue Feb 2, 2021 · 5 comments
Labels

Comments

@lindeberg
Copy link

Background

We want to query on a date range. We have read that the way to do that is by using the DateTime Ticks. We have set up code for adding the field definition and setting the value set on the index. When executing the querying code, it works as expected in our local development environment. But when the same code is running on the live environment it throws an InvalidOperationException. So, we can't actually reproduce this. Even after setting up our local development environment to mirror the live environment as closely as possible; restoring the database and copying the index.

Our setup

Examine version: 1.0.6
Umbraco version: 8.11.1

In the startup of the project we are running

index.FieldDefinitionCollection.AddOrUpdate(new FieldDefinition("sortDate_sv-se", FieldDefinitionTypes.Long));

Then we are running the following to index the field:

indexingItemEventArgs.ValueSet.Set("sortDate_sv-se", sortDate.Ticks);

The query

In a query we are running

query = query.And().RangeQuery<long>(new[] {"sortDate_sv-se", DateTime.MinValue.Ticks, DateTime.Now.AddDays(-1).Ticks)

The exception

When executing the query

System.InvalidOperationException: Could not perform a range query on the field sortDate_sv-se, it's value type is Examine.LuceneEngine.Indexing.FullTextType
 at Examine.LuceneEngine.Search.LuceneSearchQuery.<>c__DisplayClass12_0`1.<RangeQueryInternal>b__0() in C:\projects\examine-qvx04\src\Examine\LuceneEngine\Search\LuceneSearchQuery.cs:line 115
   at Examine.LuceneEngine.Search.LateBoundQuery.get_Wrapped() in C:\projects\examine-qvx04\src\Examine\LuceneEngine\Search\LateBoundQuery.cs:line 13
   at Examine.LuceneEngine.Search.LateBoundQuery.ExtractTerms(ISet`1 terms) in C:\projects\examine-qvx04\src\Examine\LuceneEngine\Search\LateBoundQuery.cs:line 37
   at Lucene.Net.Search.BooleanQuery.ExtractTerms(ISet`1 terms) in d:\Lucene.Net\FullRepo\trunk\src\core\Search\BooleanQuery.cs:line 502
   at Lucene.Net.Search.BooleanQuery.ExtractTerms(ISet`1 terms) in d:\Lucene.Net\FullRepo\trunk\src\core\Search\BooleanQuery.cs:line 502
   at Lucene.Net.Search.BooleanQuery.ExtractTerms(ISet`1 terms) in d:\Lucene.Net\FullRepo\trunk\src\core\Search\BooleanQuery.cs:line 502
   at Examine.LuceneEngine.LuceneSearchResults.DoSearch(Query query, IEnumerable`1 sortField, Int32 maxResults) in C:\projects\examine-qvx04\src\Examine\LuceneEngine\LuceneSearchResults.cs:line 60
   at Examine.LuceneEngine.Search.LuceneSearchQuery.Search(Int32 maxResults) in C:\projects\examine-qvx04\src\Examine\LuceneEngine\Search\LuceneSearchQuery.cs:line 157
   at Examine.LuceneEngine.Search.LuceneBooleanOperation.Execute(Int32 maxResults)

What we've tried

  • Removed all the index files and reindexed.
  • Re-deploying the website
  • Restarting the website
@lindeberg
Copy link
Author

Are these related?
#133 Numerical range queries don't work when using lucene query syntax

Examine Search Range Query error on Date Time
(Even though this person is using DateTime to execute range query)

@Shazwazza
Copy link
Owner

Examine supports DateTime OOTB you don't need to jump through hoops to make that work and using Ticks is a very old way of doing things.

There's some docs here for doing Date range queries https://shazwazza.github.io/Examine/searching.html and there's plenty of examples in the source code: https://github.com/Shazwazza/Examine/blob/master/src/Examine.Test/Search/FluentApiTests.cs

You need to configure your fields to be the correct value type (just like a database). By default everything is simply Full Text but if you want numerical, date, etc... type fields you need to define them that way. There's some docs here about modifying field types https://shazwazza.github.io/Examine/configuration.html and also in Umbraco docs too: https://our.umbraco.com/Documentation/Reference/Searching/Examine/indexing/#changing-field-value-types

@Shazwazza
Copy link
Owner

You've mentioned this is an issue only in one of your environments which, perhaps your custom code isn't executing in that environment or some other code is switching it back?

@sayedgt
Copy link

sayedgt commented Oct 9, 2021

How to configure the field type using this document https://shazwazza.github.io/Examine/configuration.html?
I am not that much great at coding and struggling to figure out how to make it work. I have created a class ConfigureIndexOptions following that document but now I couldnt understand how to apply this configuration. I am using Examinee latest version. Any full working example will help me understand this. Thanks,

@bjarnef
Copy link
Contributor

bjarnef commented Nov 21, 2022

@Shazwazza in Umbraco v10.2.1 I have something like this:

public void Configure(string name, LuceneDirectoryIndexOptions options)
{
    switch (name)
    {
        case Umbraco.Cms.Core.Constants.UmbracoIndexes.ExternalIndexName:
            options.FieldDefinitions.TryAdd(new FieldDefinition(UmbracoExamineFieldNames.NodeNameFieldName, FieldDefinitionTypes.FullTextSortable));
            options.FieldDefinitions.TryAdd(new FieldDefinition(Constants.Examine.Course.FieldNames.CategoriesCount, FieldDefinitionTypes.Integer));
            options.FieldDefinitions.TryAdd(new FieldDefinition(Constants.Examine.Course.FieldNames.ExpirationDate, FieldDefinitionTypes.DateTime));
            break;
    }
}

and

if (expiryDate.HasValue)
{
      query.And().RangeQuery<DateOnly>(new[] { SearchField.Course.ExpirationDate },
          expiryDate.Value,
          DateOnly.MaxValue,
          minInclusive: true);
}

image

However if I use DateTime instead of DateOnly it works.

if (expiryDate.HasValue)
{
      query.And().RangeQuery<DateTime>(new[] { SearchField.Course.ExpirationDate },
          expiryDate.Value,
          DateTime.MaxValue,
          minInclusive: true);
}

I guess it should have a DateOnlyType.cs here: https://github.com/Shazwazza/Examine/tree/07d0889d6d0a9ea06b9bae34a068dcb959e3322f/src/Examine.Lucene/Indexing

I raised a new issue regarding this here: #314

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants