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

Format to use for indexing DateRangeField and proper model field type to use? #549

Open
SirMrDexter opened this issue Feb 18, 2021 · 3 comments

Comments

@SirMrDexter
Copy link
Contributor

I have been going through the docs to try and understand the right way to index DateRangeFields in Solr using SolrNet. So far I only found samples about how to query them. But none of them explain how to index them. Like what's the correct format I should send them in JSON.

I tried sending below JSON values for testing and they all are accepted with a ok response code and I can see those values when I query them as well.

"date_ranges_test":["2021-02-21T00:00:00Z", "2021-02-22T00:00:00Z"],

"date_ranges_test":[["2021-02-21T00:00:00Z", "2021-02-22T00:00:00Z"]],

"date_ranges_test":["[2021-02-21T00:00:00Z TO 2021-02-22T00:00:00Z]"],

So not sure what's correct. One thing to note is the stored values are exactly what I send, except, 2D arrays are flattened to 1D.

Also what's the model format I should use in C#. Is it a 1D array or a 2D array of DateTime objects or I am expected to create string values in a specific format.

Any help is much appreciated.

Thanks

@mausch
Copy link
Member

mausch commented Feb 18, 2021

SolrNet doesn't support DateRangeFields at the moment.
The easiest way for you to do this in your code would be a .NET DateRangeField class with a TypeConverter for serialization.

@SirMrDexter
Copy link
Contributor Author

@mausch Thanks for the suggestion. Any plans for including this in the near future. Happy to create a branch with the suggested solution to speed things up if needed.

Also I am guessing the format I should go with should be

"date_ranges_test":["[2021-02-21T00:00:00Z TO 2021-02-22T00:00:00Z]"],

Am I right?

@mausch
Copy link
Member

mausch commented Feb 22, 2021

The TypeConverter solution I mentioned is good for easily extending SolrNet externally.
If you're planning on sending a PR implementing this the way to do it would be:

  1. Write a plain DateRange class modelling the actual date range, similar to what we have with SolrNet.Location or SolrNet.Money
  2. Implement an AbstractFieldSerializer<DateRange>
  3. Register the new field serializer in https://github.com/SolrNet/SolrNet/blob/master/SolrNet/Impl/FieldSerializers/DefaultFieldSerializer.cs
  4. Implement an ISolrFieldParser
  5. Register the new field parser in https://github.com/SolrNet/SolrNet/blob/master/SolrNet/Impl/FieldParsers/DefaultFieldParser.cs
  6. Write some tests

the format I should go with should be

No idea, I've not used this Solr feature 🙂

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

No branches or pull requests

2 participants