﻿#### Sitecore 8.2 Lucene Search: Sorting by Number field with decimals issue.

### The Problem

In one of our Siteore projects we've bumped into the issue: 

By default, In the Sitecore Lucene mappings, filed type “number” got mapping to the System.Double type:

```

<fieldType type="System.Double" fieldTypeName="number" storageType="NO" indexType="TOKENIZED" vectorType="NO" boost="1f" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider"/>

```

But Lucene sorting (lucene.net) provides following sorting valid types for sorting ([https://lucenenet.apache.org/docs/3.0.3/d1/da9/class_lucene_1_1_net_1_1_search_1_1_sort.html](https://lucenenet.apache.org/docs/3.0.3/d1/da9/class_lucene_1_1_net_1_1_search_1_1_sort.html "Lucene sorting")):

**There are four possible kinds of term values which may be put into sorting fields: Integers, Longs, Floats, or Strings.**

Here's the problem: by default, “Number” field got mapping to the double, but sorting by double is not allowed in the Lucene 3.0.3 (but in the reality, we still can sort by this filed).

This leads us to the following issue when we are sorting by “Number” in the Sitecore Lucene search:

**The field type “number” with decimals in the values are sorted incorrect in Sitecore Lucene search.**

### The Solution:

To follow Lucene.net documentation: we need to have float instead of double for sorting number field (according to [https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/built-in-types-table](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/built-in-types-table "Types Table") - this is a System.Single).

Let's say we have a Number “price” field for sorting, so we need to keep this field in the index as System.Single instead of default System.Double: 

```
      
<field type="System.Single" fieldName="price" storageType="YES" indexType="TOKENIZED" vectorType="NO" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider">
<Analyzer type="Sitecore.ContentSearch.LuceneProvider.Analyzers.LowerCaseKeywordAnalyzer, Sitecore.ContentSearch.LuceneProvider"/>
</field>
 
```

And, in our index model we should describe this field as float, similar to this: 

```
      
[IndexField("price")]
[TypeConverter(typeof(IndexFieldFloatingPointNumberValueConverter))]
public virtual float Price { get; set; }
 
```

Now, Lucene search sorting (OrderBy) for this field will be working correct for Sitecore field type number with decimals in the value.

Questions or comments? Drop us a line [here](https://www.brimit.com/contact-us "Contact Brimit") and share what you think.

###### Author

[!\[daniil_side2\](https://www.brimit.com/-/jssmedia/feature/blogs/authors/daniil_side2.jpg?h=180&amp;iar=0&amp;w=360&amp;hash=B759563CA3F35642FD513A79358CC84C)
Daniil Raschupkin
Sitecore Solution Architect](https://www.brimit.com/blog/author?authors=Daniil%20Raschupkin)

#### More on Sitecore

[!\[How Vercel Will Help You Save Effort When Deploying Sophisticated Sitecore Projects\](https://www.brimit.com/-/jssmedia/project/brimit/blog/2024/vercel_cover-image.png)
#Guides#How-toDXPE-commerce
##### How Vercel Will Help You Save Effort When Deploying Sophisticated Sitecore Projects
Optimize and accelerate the development and deployment of complex multisite Sitecore projects.
Alexei Vershalovich on July 17, 2024](https://www.brimit.com/blog/how-vercel-will-help-you-save-effort-when-deploying-sophisticated-sitecore-projects)

[!\[Training Up Tomorrow's Sitecore MVPs: a Mentoring Success Story\](https://www.brimit.com/-/jssmedia/project/brimit/blog/2023/sitecore-mentoring---cover-image.png)
#How-toDXP
##### Training Up Tomorrow's Sitecore MVPs: a Mentoring Success Story
How to participate in the Sitecore Mentor program and help younger colleagues jump-start a career in Sitecore development.
Sergey Baranov on October 2, 2023](https://www.brimit.com/blog/training-up-tomorrows-sitecore-mvps)

[!\[Going Headless. Part 2: When a Headless CMS Is Your Best Bet (if you have Sitecore)\](https://www.brimit.com/-/jssmedia/project/brimit/blog/2022/headless/adobestock_456986731.jpg)
#How-toDXPE-commerce
##### Going Headless. Part 2: When a Headless CMS Is Your Best Bet (if you have Sitecore)
Discover how a headless CMS can benefit organizations that use Sitecore.
Daniil Raschupkin, Palina Trokhautsava on September 15, 2022](https://www.brimit.com/blog/going-headless-part-2-when-a-headless-cms-is-your-best-bet-if-you-have-sitecore)

![](https://bat.bing.net/action/0?ti=187017043&amp;tm=gtm002&amp;Ver=2&amp;mid=ae9b751c-fd2e-4719-9157-ceb50c04a262&amp;bo=2&amp;gtm_tag_source=1&amp;pi=0&amp;lg=en-US&amp;sw=800&amp;sh=600&amp;sc=24&amp;nwd=1&amp;tl=Sitecore%208.2%20Lucene%20Search%3A%20Sorting%20by%20Number%20field%20with%20decimals%20issue.&amp;kw=Sitecore,%20Lucene,%20Search,%20Sorting,%20Number,%20field,%20decimal,%20issue,%20sort%20by%20number%20&amp;p=https%3A%2F%2Fwww.brimit.com%2Fblog%2Fsitecore-lucene-search-sorting-decimal&amp;r=&amp;lt=253&amp;evt=pageLoad&amp;sv=2&amp;asc=D&amp;cdb=AQAY&amp;rn=322043)