-
Notifications
You must be signed in to change notification settings - Fork 242
/
AbstractLuceneStandardFieldSortBuilderFactory.java
61 lines (49 loc) · 2.13 KB
/
AbstractLuceneStandardFieldSortBuilderFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* 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.backend.lucene.types.sort.impl;
import java.lang.invoke.MethodHandles;
import org.hibernate.search.backend.lucene.logging.impl.Log;
import org.hibernate.search.backend.lucene.search.sort.impl.LuceneSearchSortBuilder;
import org.hibernate.search.backend.lucene.types.converter.impl.LuceneFieldConverter;
import org.hibernate.search.engine.logging.spi.EventContexts;
import org.hibernate.search.engine.search.sort.spi.DistanceSortBuilder;
import org.hibernate.search.engine.spatial.GeoPoint;
import org.hibernate.search.util.impl.common.LoggerFactory;
abstract class AbstractLuceneStandardFieldSortBuilderFactory<T> implements LuceneFieldSortBuilderFactory {
private static final Log log = LoggerFactory.make( Log.class, MethodHandles.lookup() );
private final boolean sortable;
protected final LuceneFieldConverter<?, T> converter;
protected AbstractLuceneStandardFieldSortBuilderFactory(boolean sortable, LuceneFieldConverter<?, T> converter) {
this.sortable = sortable;
this.converter = converter;
}
@Override
public DistanceSortBuilder<LuceneSearchSortBuilder> createDistanceSortBuilder(String absoluteFieldPath,
GeoPoint center) {
throw log.distanceOperationsNotSupportedByFieldType(
EventContexts.fromIndexFieldAbsolutePath( absoluteFieldPath )
);
}
@Override
public boolean isDslCompatibleWith(LuceneFieldSortBuilderFactory obj) {
if ( this == obj ) {
return true;
}
if ( obj.getClass() != this.getClass() ) {
return false;
}
AbstractLuceneStandardFieldSortBuilderFactory<?> other = (AbstractLuceneStandardFieldSortBuilderFactory<?>) obj;
return sortable == other.sortable &&
converter.isConvertDslToIndexCompatibleWith( other.converter );
}
protected void checkSortable(String absoluteFieldPath) {
if ( !sortable ) {
throw log.unsortableField( absoluteFieldPath,
EventContexts.fromIndexFieldAbsolutePath( absoluteFieldPath ) );
}
}
}