Skip to content

Instantly share code, notes, and snippets.

@gunnarmorling
Last active September 7, 2015 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gunnarmorling/4ab262cf1fc772047897 to your computer and use it in GitHub Desktop.
Save gunnarmorling/4ab262cf1fc772047897 to your computer and use it in GitHub Desktop.
@Field(analyzed=Analyze.NO)
@SortField
public String getLastname() {
return lastname;
}
@Fields({
@Field,
@Field(name="unanalyzed", analyzed=Analyze.NO)
})
@SortField(forField="unanalyzed")
public String getLastname() {
return lastname;
}
@Field(analyzed=Analyze.NO)
@SortField(name="last_name_sort_field")
public String getLastname() {
return lastname;
}
// for a field which should be *sortable* but *not searchable* (it's unstored and unindexed ) I
// still need a field definition in my current local branch to get the value via the field
// bridge; This field will not be added to the index itself, only the doc value field used for
// sorting will be added
@Field(analyzed=Analyze.NO, store=Store.NO, indexed=Index.NO)
@SortField
public String getLastname() {
return lastname;
}
// Alternatively, one could add fieldBridge() / indexNullAs() to @SortField so one omit the field in that case:
@SortField(fieldBridge=MyFieldBridge.class)
public String getLastname() {
return lastname;
}
/*
* Hibernate Search, full-text search for your domain model
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.search.annotations;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Makes a property sortable.
* <p>
* A document field for that property must exist from which the field bridge configuration will be inherited. In the
* rare case that a property should be sortable but not searchable, declare a field which is not indexed nor stored.
* Then only the sort field will be added to the document, but no standard index field.
*
* @author Gunnar Morling
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.FIELD })
@Documented
public @interface SortField {
/**
* Name of the sort field in the index. Defaults to the name of the field upon which this sort field is based.
*/
String name() default "";
/**
* Name of the document field whose field bridge to apply to obtain the value of this sort field. Can be omitted in
* case only a single field exists for the annotated property.
*/
String forField() default "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment