# Could not add sortable annotation on some analysed field?

**URL:** <https://discourse.hibernate.org/t/could-not-add-sortable-annotation-on-some-analysed-field/1141>\
**Category:** Hibernate Search\
**Created:** [July 31, 2018, 6:51am UTC](https://discourse.hibernate.org/t/could-not-add-sortable-annotation-on-some-analysed-field/1141 "2018-07-31T06:51:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Sun](https://avatars.discourse-cdn.com/v4/letter/m/f07891/32.png) [@Michael\_Sun](https://discourse.hibernate.org/u/Michael_Sun)\
**Post date:** [July 31, 2018, 6:51am UTC](https://discourse.hibernate.org/t/could-not-add-sortable-annotation-on-some-analysed-field/1141/1 "2018-07-31T06:51:51Z")

</div>

```auto
@Column(nullable = false, length = 50)
    @Fields({
            @Field(name = "firstName", index = Index.YES, analyze = Analyze.YES, analyzer = @Analyzer(definition = "nameAnalyzer")),
            @Field(name = "dummyFieldToAddQueryAnalyzer", index = Index.YES, analyze = Analyze.YES, analyzer = @Analyzer(definition = "nameAnalyzer_query"), bridge = @FieldBridge(impl = DummyStringBridge.class))
    })
    private String firstName;

```

Now I have a `firstName` field for searching, indexing and analysed, but now I want to make this field sortable, say sort by first name, I am not able to add `@SortableField`, because sort fields must not be analyzed, right?

How can I do that? any other tricks?

---

<div class="post-metadata">

**Author:** ![yrodiere](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/yrodiere/32/1760_2.png) [@yrodiere](https://discourse.hibernate.org/u/yrodiere)\
**Post date:** [July 31, 2018, 7:34am UTC](https://discourse.hibernate.org/t/could-not-add-sortable-annotation-on-some-analysed-field/1141/2 "2018-07-31T07:34:54Z")

</div>

Just add another field:

```auto
@Column(nullable = false, length = 50)
@Fields({
    @Field(name = "firstName", analyzer = @Analyzer(definition = "nameAnalyzer")),
    @Field(name = "firstName_sort"),
    @Field(name = "dummyFieldToAddQueryAnalyzer", analyzer = @Analyzer(definition = "nameAnalyzer_query"), bridge = @FieldBridge(impl = DummyStringBridge.class))
})
@SortableField(forField = "fieldName_sort")
private String firstName;

```

Then when you need a sort, you will have to sort on `fieldName_sort`.

Optionally, and provided you are using a recent version of Hibernate Search, you can [use a normalizer](https://docs.jboss.org/hibernate/search/5.10/reference/en-US/html_single/#section-normalizers) on the sort field. Analyzers are forbidden on sort fields, but normalizers are allowed, since they cannot produce multiple tokens.
