Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd797dcd

Browse files
committed
- extended API to allow more facet parameters
- create Buckets for better handling of the result from json.facet
1 parent0e857ba commitd797dcd

File tree

5 files changed

+162
-9
lines changed

5 files changed

+162
-9
lines changed

‎src/main/java/com/indoqa/solr/facet/api/AbstractFacet.java‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public abstract class AbstractFacet implements Facet {
3030

3131
privateStringname;
3232
privateStringtype;
33+
3334
protectedList<Facet>subFacets =newArrayList<>();
3435

3536
publicAbstractFacet(Stringtype,Stringname) {
@@ -75,8 +76,8 @@ public String toJsonString() {
7576
returncharArr.toString();
7677
}
7778

78-
protectedvoidwriteBooleanField(JSONWriterjsonWriter,Stringname,booleanvalue) {
79-
jsonWriter.write(name);
79+
protectedvoidwriteBooleanField(JSONWriterjsonWriter,StringfieldName,booleanvalue) {
80+
jsonWriter.write(fieldName);
8081
jsonWriter.writeNameSeparator();
8182
jsonWriter.write(value);
8283
}
@@ -93,14 +94,14 @@ protected void writeFacets(JSONWriter jsonWriter, List<Facet> facets) {
9394
}
9495
}
9596

96-
protectedvoidwriteNumberField(JSONWriterjsonWriter,Stringname,Numbervalue) {
97-
jsonWriter.write(name);
97+
protectedvoidwriteNumberField(JSONWriterjsonWriter,StringfieldName,Numbervalue) {
98+
jsonWriter.write(fieldName);
9899
jsonWriter.writeNameSeparator();
99100
jsonWriter.write(value);
100101
}
101102

102-
protectedvoidwriteStringField(JSONWriterjsonWriter,Stringname,Stringvalue) {
103-
jsonWriter.write(name);
103+
protectedvoidwriteStringField(JSONWriterjsonWriter,StringfieldName,Stringvalue) {
104+
jsonWriter.write(fieldName);
104105
jsonWriter.writeNameSeparator();
105106
jsonWriter.write(value);
106107
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Licensed to the Indoqa Software Design und Beratung GmbH (Indoqa) under
3+
* one or more contributor license agreements. See the NOTICE file distributed
4+
* with this work for additional information regarding copyright ownership.
5+
* Indoqa licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
packagecom.indoqa.solr.facet.api;
18+
19+
importjava.util.Collections;
20+
importjava.util.Iterator;
21+
importjava.util.List;
22+
23+
importorg.apache.solr.client.solrj.response.QueryResponse;
24+
importorg.apache.solr.common.util.NamedList;
25+
26+
publicclassBucketsimplementsIterable<NamedList<Object>> {
27+
28+
privatefinalList<NamedList<Object>>buckets;
29+
privatefinalintnumBuckets;
30+
31+
publicBuckets(List<NamedList<Object>>buckets,intnumBuckets) {
32+
super();
33+
34+
this.buckets =buckets;
35+
this.numBuckets =numBuckets;
36+
}
37+
38+
@SuppressWarnings("unchecked")
39+
publicstaticBucketsfromFacet(NamedList<Object>facet) {
40+
if (facet ==null) {
41+
returnnewBuckets(Collections.<NamedList<Object>>emptyList(),0);
42+
}
43+
44+
List<NamedList<Object>>buckets = (List<NamedList<Object>>)facet.get("buckets");
45+
if (buckets ==null) {
46+
returnnewBuckets(Collections.<NamedList<Object>>emptyList(),0);
47+
}
48+
49+
intnumBuckets =getInt(facet,"numBuckets", -1);
50+
returnnewBuckets(buckets,numBuckets);
51+
}
52+
53+
@SuppressWarnings("unchecked")
54+
publicstaticBucketsfromResponse(QueryResponsequeryResponse,StringfacetName) {
55+
NamedList<Object>facets = (NamedList<Object>)queryResponse.getResponse().get("facets");
56+
if (facets ==null) {
57+
returnnewBuckets(Collections.<NamedList<Object>>emptyList(),0);
58+
}
59+
60+
NamedList<Object>facet = (NamedList<Object>)facets.get(facetName);
61+
returnfromFacet(facet);
62+
}
63+
64+
publicstaticintgetInt(NamedList<?>list,Stringname) {
65+
return ((Number)list.get(name)).intValue();
66+
}
67+
68+
publicstaticintgetInt(NamedList<?>list,Stringname,intdefaultValue) {
69+
Objectvalue =list.get(name);
70+
if (value ==null) {
71+
returndefaultValue;
72+
}
73+
74+
return ((Number)value).intValue();
75+
}
76+
77+
publicNamedList<Object>getBucket(intindex) {
78+
returnthis.buckets.get(index);
79+
}
80+
81+
publicintgetBucketCount() {
82+
returnthis.buckets.size();
83+
}
84+
85+
publicintgetNumBuckets() {
86+
returnthis.numBuckets;
87+
}
88+
89+
@Override
90+
publicIterator<NamedList<Object>>iterator() {
91+
returnthis.buckets.iterator();
92+
}
93+
}

‎src/main/java/com/indoqa/solr/facet/api/FacetList.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ public FacetList() {
2424
super(null,null);
2525
}
2626

27+
publicstaticStringtoJsonString(Facetfacet) {
28+
FacetListfacetList =newFacetList();
29+
30+
facetList.addSubFacet(facet);
31+
32+
returnfacet.toJsonString();
33+
}
34+
2735
@Override
2836
publicvoidstreamToJson(JSONWriterjsonWriter) {
2937
if (this.subFacets.isEmpty()) {

‎src/main/java/com/indoqa/solr/facet/api/RangeFacet.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
packagecom.indoqa.solr.facet.api;
1818

1919
importjava.io.IOException;
20-
importjava.util.Calendar;
2120
importjava.util.Date;
2221

2322
importorg.apache.solr.common.util.DateUtil;
@@ -62,7 +61,7 @@ protected void writeFacetConfiguration(JSONWriter jsonWriter) {
6261
privateStringtoString(Datedate) {
6362
try {
6463
StringBuilderstringBuilder =newStringBuilder();
65-
DateUtil.formatDate(date,Calendar.getInstance(),stringBuilder);
64+
DateUtil.formatDate(date,null,stringBuilder);
6665
returnstringBuilder.toString();
6766
}catch (IOExceptione) {
6867
thrownewFacetMarshallingException(e);

‎src/main/java/com/indoqa/solr/facet/api/TermsFacet.java‎

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,23 @@
2121
publicclassTermsFacetextendsAbstractFacet {
2222

2323
privatestaticfinalStringTYPE_TERMS ="terms";
24+
25+
privatestaticfinalStringPARAM_SORT ="sort";
2426
privatestaticfinalStringPARAM_LIMIT ="limit";
2527
privatestaticfinalStringPARAM_FIELD ="field";
28+
privatestaticfinalStringPARAM_OFFSET ="offset";
29+
privatestaticfinalStringPARAM_MINCOUNT ="mincount";
2630
privatestaticfinalStringPARAM_NUM_BUCKETS ="numBuckets";
2731

28-
privateIntegerlimit;
2932
privatefinalStringfield;
33+
34+
privateIntegerlimit;
35+
privateIntegeroffset;
36+
privateIntegermincount;
3037
privatebooleannumBuckets;
3138

39+
privateStringsort;
40+
3241
publicTermsFacet(Stringname,Stringfield) {
3342
this(name,field,null);
3443
}
@@ -40,19 +49,62 @@ public TermsFacet(String name, String field, Integer limit) {
4049
this.limit =limit;
4150
}
4251

52+
publicIntegergetLimit() {
53+
returnthis.limit;
54+
}
55+
56+
publicIntegergetMincount() {
57+
returnthis.mincount;
58+
}
59+
60+
publicIntegergetOffset() {
61+
returnthis.offset;
62+
}
63+
64+
publicvoidsetLimit(Integerlimit) {
65+
this.limit =limit;
66+
}
67+
68+
publicvoidsetMincount(Integermincount) {
69+
this.mincount =mincount;
70+
}
71+
4372
publicvoidsetNumBuckets(booleannumBuckets) {
4473
this.numBuckets =numBuckets;
4574
}
4675

76+
publicvoidsetOffset(Integeroffset) {
77+
this.offset =offset;
78+
}
79+
80+
publicvoidsetSort(Stringsort) {
81+
this.sort =sort;
82+
}
83+
4784
@Override
4885
protectedvoidwriteFacetConfiguration(JSONWriterjsonWriter) {
4986
this.writeStringField(jsonWriter,PARAM_FIELD,this.field);
5087

88+
if (this.sort !=null) {
89+
this.writeValueSeparator(jsonWriter);
90+
this.writeStringField(jsonWriter,PARAM_SORT,this.sort);
91+
}
92+
93+
if (this.offset !=null) {
94+
this.writeValueSeparator(jsonWriter);
95+
this.writeNumberField(jsonWriter,PARAM_OFFSET,this.offset);
96+
}
97+
5198
if (this.limit !=null) {
5299
this.writeValueSeparator(jsonWriter);
53100
this.writeNumberField(jsonWriter,PARAM_LIMIT,this.limit);
54101
}
55102

103+
if (this.mincount !=null) {
104+
this.writeValueSeparator(jsonWriter);
105+
this.writeNumberField(jsonWriter,PARAM_MINCOUNT,this.mincount);
106+
}
107+
56108
if (this.numBuckets) {
57109
this.writeValueSeparator(jsonWriter);
58110
this.writeBooleanField(jsonWriter,PARAM_NUM_BUCKETS,this.numBuckets);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp