Skip to content

Commit 4f7ea01

Browse files
ahornaceVladimir Kotal
authored andcommitted
Add possibility to retrieve all the popularity data at once
1 parent 9b91318 commit 4f7ea01

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/org/opensolaris/opengrok/web/api/v1/controller/SuggesterController.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.lucene.index.Term;
2626
import org.apache.lucene.queryparser.classic.ParseException;
2727
import org.apache.lucene.search.Query;
28+
import org.apache.lucene.util.BytesRef;
2829
import org.hibernate.validator.constraints.NotBlank;
2930
import org.opengrok.suggest.LookupResultItem;
3031
import org.opengrok.suggest.Suggester.Suggestions;
@@ -187,7 +188,7 @@ public void addSearchCountsQueries(final List<String> urls) {
187188
continue;
188189
}
189190
if (fieldQueryText.size() > 2) {
190-
logger.log(Level.WARNING, "Bad format, ignoring");
191+
logger.log(Level.WARNING, "Bad format, ignoring {0}", urlStr);
191192
continue;
192193
}
193194
String value = fieldQueryText.get(0);
@@ -267,9 +268,16 @@ public List<Entry<String, Integer>> getPopularityDataPaged(
267268
@PathParam("project") final String project,
268269
@QueryParam("field") @DefaultValue(QueryBuilder.FULL) final String field,
269270
@QueryParam("page") @DefaultValue("" + 0) final int page,
270-
@QueryParam("pageSize") @DefaultValue("" + POPULARITY_DEFAULT_PAGE_SIZE) final int pageSize
271+
@QueryParam("pageSize") @DefaultValue("" + POPULARITY_DEFAULT_PAGE_SIZE) final int pageSize,
272+
@QueryParam("all") final boolean all
271273
) {
272-
return suggester.getPopularityData(project, field, page, pageSize).stream()
274+
List<Entry<BytesRef, Integer>> data;
275+
if (all) {
276+
data = suggester.getPopularityData(project, field, 0, Integer.MAX_VALUE);
277+
} else {
278+
data = suggester.getPopularityData(project, field, page, pageSize);
279+
}
280+
return data.stream()
273281
.map(e -> new SimpleEntry<>(e.getKey().utf8ToString(), e.getValue()))
274282
.collect(Collectors.toList());
275283
}

test/org/opensolaris/opengrok/web/api/v1/controller/SuggesterControllerTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,24 @@ public void testGetPopularityDataSimple() {
587587
assertThat(res, contains(new SimpleEntry<>("main", 10)));
588588
}
589589

590+
@Test
591+
public void testGetPopularityDataAll() {
592+
SuggesterServiceImpl.getInstance().increaseSearchCount("csharp",
593+
new Term(QueryBuilder.FULL, "mynamespace"), 10);
594+
SuggesterServiceImpl.getInstance().increaseSearchCount("csharp",
595+
new Term(QueryBuilder.FULL, "topclass"), 15);
596+
597+
List<Entry<String, Integer>> res = target(SuggesterController.PATH)
598+
.path("popularity")
599+
.path("csharp")
600+
.queryParam("pageSize", 1)
601+
.queryParam("all", true)
602+
.request()
603+
.get(popularityDataType);
604+
605+
assertThat(res, contains(new SimpleEntry<>("stopclass", 15), new SimpleEntry<>("mynamespace", 10)));
606+
}
607+
590608
@Test
591609
public void testGetPopularityDataDifferentField() {
592610
SuggesterServiceImpl.getInstance().increaseSearchCount("swift", new Term(QueryBuilder.FULL, "print"), 10);

0 commit comments

Comments
 (0)