Skip to content

Commit 9743b72

Browse files
committed
Update v2.1.3
1 parent 5b8e399 commit 9743b72

File tree

9 files changed

+103
-125
lines changed

9 files changed

+103
-125
lines changed

src/main/java/tla/backend/es/model/LemmaEntity.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
import tla.backend.es.model.parts.Transcription;
2828
import tla.backend.es.model.parts.Glyphs;
2929
import tla.domain.dto.LemmaDto;
30+
import tla.domain.dto.LemmaDto.TimeSpan;
3031
import tla.domain.model.meta.BTSeClass;
3132
import tla.domain.model.meta.TLADTO;
3233

3334
@Data
34-
@SuperBuilder
3535
@TLADTO(LemmaDto.class)
3636
@BTSeClass("BTSLemmaEntry")
3737
@ToString(callSuper = true)
@@ -59,7 +59,7 @@ public class LemmaEntity extends TLAEntity {
5959

6060
@Field(type = FieldType.Object)
6161
@JsonAlias({"time_span"})
62-
private AttestedTimeSpan timeSpan;
62+
private TimeSpan timeSpan;
6363

6464
@Field(type = FieldType.Keyword)
6565
private Integer attestedSentencesCount;
@@ -71,18 +71,4 @@ public class LemmaEntity extends TLAEntity {
7171
public LemmaEntity() {
7272
this.words = Collections.emptyList();
7373
}
74-
75-
@Getter
76-
@Setter
77-
@NoArgsConstructor
78-
@AllArgsConstructor
79-
@JsonInclude(Include.NON_NULL)
80-
public static class AttestedTimeSpan {
81-
82-
@Field(type = FieldType.Integer)
83-
private Integer begin;
84-
85-
@Field(type = FieldType.Integer)
86-
private Integer end;
87-
}
8874
}

src/main/java/tla/backend/es/model/SentenceEntity.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static class Context {
108108
@Field(type = FieldType.Text)
109109
private String paragraph;
110110
/**
111-
* This sentence's positon in the containing text's array of sentences, starting
111+
* This sentence's position in the containing text's array of sentences, starting
112112
* with <code>0</code>.
113113
*/
114114
@JsonAlias("pos")
@@ -118,7 +118,17 @@ public static class Context {
118118
* How many variants of a single sentences exist (due to ambivalences).
119119
*/
120120
@Field(type = FieldType.Integer)
121-
private int variants;
121+
private int variants;
122+
/**
123+
* Latest possible date
124+
*/
125+
@Field(type = FieldType.Integer)
126+
private int notAfter;
127+
/**
128+
* Earliest possible date
129+
*/
130+
@Field(type = FieldType.Integer)
131+
private int notBefore;
122132
}
123133

124134
}

src/main/java/tla/backend/es/model/ThsEntryEntity.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import tla.backend.es.model.parts.Translations;
2727
import tla.domain.dto.ThsEntryDto;
2828
import tla.domain.model.Passport;
29-
import tla.domain.model.extern.AttestedTimespan;
3029
import tla.domain.model.meta.BTSeClass;
3130
import tla.domain.model.meta.TLADTO;
3231

@@ -144,16 +143,4 @@ public List<Integer> extractTimespan() {
144143
Collections.sort(years);
145144
return years;
146145
}
147-
148-
/**
149-
* creates a DTO object representing the timespan covered by a thesaurus term.
150-
*/
151-
public AttestedTimespan.Period toAttestedPeriod() {
152-
List<Integer> years = this.extractTimespan();
153-
return AttestedTimespan.Period.builder()
154-
.begin(years.get(0))
155-
.end(years.get(1))
156-
.ref(this.toDTOReference())
157-
.build();
158-
}
159146
}

src/main/java/tla/backend/es/model/meta/ModelConfig.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import tla.domain.dto.ThsEntryDto;
4848
import tla.domain.dto.meta.AbstractDto;
4949
import tla.domain.model.SentenceToken;
50-
import tla.domain.model.extern.AttestedTimespan;
5150
import tla.domain.model.meta.AbstractBTSBaseClass;
5251
import tla.domain.model.meta.BTSeClass;
5352
import tla.domain.model.meta.TLADTO;
@@ -256,7 +255,6 @@ protected static ModelMapper initModelMapper() {
256255
).addMapping(
257256
LemmaEntity::getRevisionState, LemmaDto::setReviewState
258257
);
259-
modelMapper.createTypeMap(LemmaEntity.AttestedTimeSpan.class, AttestedTimespan.Period.class);
260258
modelMapper.createTypeMap(ThsEntryEntity.class, ThsEntryDto.class)
261259
.addMappings(
262260
m -> m.using(translationsToMapConverter).map(

src/main/java/tla/backend/es/query/ESQueryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public NativeSearchQuery buildNativeSearchQuery(Pageable page) {
5454
).withTrackTotalHits(
5555
page.isPaged()
5656
).withSorts(
57-
this.getSortSpec().primary()
57+
this.sortSpec.Sorting()
5858
);
5959
log.info("query: {}", this.getNativeRootQueryBuilder());
6060
this.getNativeAggregationBuilders().forEach(

src/main/java/tla/backend/es/query/LemmaSearchQueryBuilder.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010

1111
import org.elasticsearch.index.query.BoolQueryBuilder;
1212
import org.elasticsearch.index.query.Operator;
13+
import org.elasticsearch.search.sort.SortOrder;
1314

1415
import lombok.Getter;
1516
import tla.backend.es.model.LemmaEntity;
17+
import tla.backend.es.query.SortSpec.FieldOrder;
1618
import tla.backend.service.ModelClass;
1719
import tla.domain.command.TypeSpec;
1820
import tla.domain.command.TranscriptionSpec;
@@ -228,10 +230,12 @@ public void setBibliography(String bibliography) {
228230

229231
public void setSort(String sort) {
230232
super.setSort(sort);
231-
if (sortSpec.field.equals("root")) {
232-
sortSpec.field = "relations.root.name";
233+
if (sortSpec.FieldOrders.get(0).equals("root")) {
234+
sortSpec.FieldOrders.get(0).field = "relations.root.name";
233235
}
234-
// nicht einheitlich/elegant gel?st: die anderen vier Suchf?lle sind so gel?st,
236+
sortSpec.addFieldOrder(new FieldOrder("sortKey", SortOrder.ASC));
237+
238+
// nicht einheitlich/elegant gel?st: die anderen vier Suchf?lle sind so gel?st,
235239
// dass in der URL der Name der Variablen erscheint ("sortKey" bzw. "timeSpan.begin",
236240
// gefolgt von "_asc"/"_desc", aber nicht hier bei "relations.root.name"
237241
// die Angaben in der URL sollten generell sprechend sein "transliteration_asc", ..., "timespan_asc", ...

src/main/java/tla/backend/es/query/SentenceSearchQueryBuilder.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
import org.apache.lucene.search.join.ScoreMode;
88
import org.elasticsearch.index.query.BoolQueryBuilder;
99
import org.elasticsearch.index.query.QueryBuilders;
10+
import org.elasticsearch.search.sort.SortOrder;
1011

1112
import lombok.Getter;
1213
import lombok.extern.slf4j.Slf4j;
1314
import tla.backend.es.model.SentenceEntity;
1415
import tla.backend.es.model.SentenceEntity.Context;
1516
import tla.backend.es.model.parts.Token;
17+
import tla.backend.es.query.SortSpec.FieldOrder;
1618
import tla.backend.service.ModelClass;
1719
import tla.domain.command.PassportSpec;
1820
import tla.domain.command.SentenceSearch.TokenSpec;
@@ -23,6 +25,13 @@
2325
public class SentenceSearchQueryBuilder extends ESQueryBuilder implements MultiLingQueryBuilder {
2426

2527
public final static String AGG_ID_TEXT_IDS = "text_ids";
28+
29+
public void setSort(String sort) {
30+
super.setSort(sort);
31+
sortSpec.addFieldOrder(new FieldOrder("context.textId", SortOrder.ASC));
32+
sortSpec.addFieldOrder(new FieldOrder("context.position", SortOrder.ASC));
33+
}
34+
2635

2736
public void setContext(Context context) {
2837
BoolQueryBuilder textQuery = boolQuery();
@@ -35,6 +44,8 @@ public void setContext(Context context) {
3544
}
3645

3746
}
47+
48+
3849

3950
/* public void setTokens(Collection<Token> tokens) {
4051
if (tokens != null) {
Lines changed: 67 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tla.backend.es.query;
22

33
import java.util.Arrays;
4+
import java.util.ArrayList;
45

56
import org.elasticsearch.search.sort.ScoreSortBuilder;
67
import org.elasticsearch.search.sort.SortBuilder;
@@ -14,73 +15,79 @@
1415
* Representation of search order specifications.
1516
*/
1617
@NoArgsConstructor
17-
@AllArgsConstructor
1818
public class SortSpec {
1919

20-
public static final String DELIMITER = "_";
21-
/**
22-
* an empty sort specification instance, whose {@link #primary()} method just returns
23-
* a standard {@link ScoreSortBuilder}.
24-
*/
25-
public static final SortSpec DEFAULT = new SortSpec();
20+
public static final String DELIMITER = "_";
21+
/**
22+
* an empty sort specification instance, whose {@link #primary()} method just
23+
* returns a standard {@link ScoreSortBuilder}.
24+
*/
25+
public static final SortSpec DEFAULT = new SortSpec();
2626

27-
/**
28-
* name of field by whose value to order.
29-
*/
30-
protected String field;
31-
/**
32-
* sort order (i.e. {@link SortOrder.ASC} or {@link SortOrder.DESC})
33-
*/
34-
protected SortOrder order;
27+
protected ArrayList<FieldOrder> FieldOrders = new ArrayList<FieldOrder>();
3528

36-
/**
37-
* Create new sort spec configured for ascending order ({@link SortOrder.ASC}) on given field.
38-
*/
39-
public SortSpec(String field) {
40-
this(field, SortOrder.ASC);
41-
}
29+
/**
30+
* Create new sort spec configured for ascending order ({@link SortOrder.ASC})
31+
* on given field.
32+
*/
33+
public SortSpec(FieldOrder FieldOrder) {
34+
this.FieldOrders.add(FieldOrder);
35+
}
4236

43-
/**
44-
* Create a new sort specification instance with given field name and sort order (<code>"asc"</code>/<code>"desc"</code>).
45-
*/
46-
public SortSpec(String field, String order) {
47-
this(
48-
field,
49-
order.toLowerCase().equals("desc") ? SortOrder.DESC : SortOrder.ASC
50-
);
51-
}
37+
public SortSpec(ArrayList<FieldOrder> FieldOrders) {
38+
this.FieldOrders = FieldOrders;
39+
}
5240

53-
/**
54-
* Create a sort spec instance from a string consisting of a field name, followed by an order specifier (asc/desc),
55-
* seperated by the delimiter character defined in {@link #DELIMITER}.
56-
*/
57-
public static SortSpec from(String source) {
58-
if (source != null) {
59-
String[] segm = source.split(DELIMITER);
60-
String field = String.join(
61-
DELIMITER,
62-
Arrays.asList(segm).subList(0, segm.length - 1)
63-
);
64-
if (segm.length > 1) {
65-
return new SortSpec(field, segm[segm.length - 1]);
66-
} else {
67-
return new SortSpec(segm[0]);
68-
}
69-
} else {
70-
return new SortSpec("id");
71-
}
72-
}
41+
public void addFieldOrder(FieldOrder FieldOrder) {
42+
this.FieldOrders.add(FieldOrder);
43+
}
7344

74-
public SortBuilder<?> primary() {
75-
if (this.field != null) {
76-
return SortBuilders.fieldSort(this.field).order(this.order);
77-
} else {
78-
return SortBuilders.scoreSort();
79-
}
80-
}
45+
public static class FieldOrder {
46+
/**
47+
* name of field by whose value to order.
48+
*/
49+
protected String field;
50+
/**
51+
* sort order (i.e. {@link SortOrder.ASC} or {@link SortOrder.DESC})
52+
*/
53+
protected SortOrder order;
8154

82-
public SortBuilder<?> secondary() {
83-
return SortBuilders.fieldSort("id").order(this.order);
84-
}
55+
public FieldOrder(String field, SortOrder order) {
56+
this.field = field;
57+
this.order = order;
58+
}
59+
}
8560

61+
/**
62+
* Create a sort spec instance from a string consisting of a field name,
63+
* followed by an order specifier (asc/desc), seperated by the delimiter
64+
* character defined in {@link #DELIMITER}.
65+
*/
66+
public static SortSpec from(String source) {
67+
68+
if (source != null) {
69+
String[] segm = source.split(DELIMITER);
70+
String field = String.join(DELIMITER, Arrays.asList(segm).subList(0, segm.length - 1));
71+
;
72+
if (segm.length > 1) {
73+
if (segm[segm.length - 1].equals("asc")) {
74+
return new SortSpec(new FieldOrder(field, SortOrder.ASC));
75+
} else {
76+
return new SortSpec(new FieldOrder(field, SortOrder.DESC));
77+
}
78+
} else {
79+
return new SortSpec(new FieldOrder(segm[0], SortOrder.ASC));
80+
}
81+
} else {
82+
return new SortSpec(new FieldOrder("id", SortOrder.ASC));
83+
}
84+
}
85+
86+
public ArrayList<SortBuilder<?>> Sorting() {
87+
ArrayList<SortBuilder<?>> allSortBuilders = new ArrayList<SortBuilder<?>>();
88+
for (FieldOrder fieldOrder : FieldOrders) {
89+
allSortBuilders.add(SortBuilders.fieldSort(fieldOrder.field).order(fieldOrder.order));
90+
}
91+
return allSortBuilders;
92+
}
8693
}

src/main/java/tla/backend/service/LemmaService.java

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@
3232
import tla.domain.dto.extern.SingleDocumentWrapper;
3333
import tla.domain.dto.meta.AbstractDto;
3434
import tla.domain.model.Language;
35-
import tla.domain.model.extern.AttestedTimespan;
36-
import tla.domain.model.extern.AttestedTimespan.AttestationStats;
37-
import tla.domain.model.extern.AttestedTimespan.Period;
35+
3836

3937
@Service
4038
@ModelClass(value = LemmaEntity.class, path = "lemma")
@@ -60,41 +58,18 @@ public ElasticsearchRepository<LemmaEntity, String> getRepo() {
6058
* that lemma attestations are computed from occurrences and put into the
6159
* wrapped lemma DTO.
6260
*
63-
* @see {@link #computeAttestedTimespans(String)}
61+
* @see {@link #setAttestationsAndPeriod(String)}
6462
*/
6563
@Override
6664
public SingleDocumentWrapper<? extends AbstractDto> getDetails(String id) {
6765
LemmaEntity lemma = retrieve(id);
6866
if (lemma == null) {
6967
return null;
7068
}
71-
SingleDocumentWrapper<?> wrapper = super.getDetails(id);
72-
((LemmaDto) wrapper.getDoc()).setAttestations(
73-
this.computeAttestedTimespans((LemmaDto) wrapper.getDoc())
74-
);
69+
SingleDocumentWrapper<?> wrapper = super.getDetails(id);
7570
return wrapper;
7671
}
7772

78-
/**
79-
* count sentences and texts containing the specified lemma.
80-
*/
81-
public List<AttestedTimespan> computeAttestedTimespans(LemmaDto dto) {
82-
ESQueryResult<?> sentenceSearchResult = searchService.register(
83-
new SentencesContainingLemmaOccurrenceQueryBuilder(dto.getId())
84-
).run(SearchService.UNPAGED);
85-
Period attestedPeriod = dto.getTimeSpan();
86-
AttestationStats counts = AttestationStats.builder().count(0
87-
//sentenceSearchResult.getAggregation(SentenceSearchQueryBuilder.AGG_ID_TEXT_IDS).size()
88-
).texts(0
89-
//sentenceSearchResult.getAggregation(SentenceSearchQueryBuilder.AGG_ID_TEXT_IDS).size()
90-
).sentences(
91-
sentenceSearchResult.getHitCount()
92-
).build();
93-
return List.of(
94-
AttestedTimespan.builder().period(attestedPeriod).attestations(counts).build()
95-
);
96-
}
97-
9873
public Map<String, Long> getMostFrequent(int limit) {
9974
SearchResponse response = this.searchService.query(SentenceEntity.class, matchAllQuery(),
10075
AggregationBuilders.nested("aggs", "tokens").subAggregation(AggregationBuilders.terms("lemmata")

0 commit comments

Comments
 (0)