Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft for add facette for collections #2109 #2122

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions web/app/controllers/resources/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public class Application extends Controller {
public static final String OWNER_AGGREGATION = "hasItem.heldBy.id";
/** The internal ES field for the topics. */
public static final String TOPIC_AGGREGATION = "subject.label.raw";
/** The internal ES field for the topics. */
public static final String COLLECTION_AGGREGATION = "inCollection.label.raw";
/** The internal ES field for subjects. */
public static final String SUBJECT_FIELD = "subject.componentList.id";
/** The internal ES field for contributing agents. */
Expand Down Expand Up @@ -174,6 +176,7 @@ public static String currentUri() {
* @param publisher Query for the resource publisher
* @param issued Query for the resource issued year
* @param medium Query for the resource medium
* @param collection Query for the resource collection *
* @param from The page start (offset of page of resource to return)
* @param size The page size (size of page of resource to return)
* @param owner Owner filter for resource queries
Expand All @@ -189,7 +192,7 @@ public static String currentUri() {
*/
public static Promise<Result> query(final String q, final String agent,
final String name, final String subject, final String id,
final String publisher, final String issued, final String medium,
final String publisher, final String issued, final String medium, final String collection,
final int from, final int size, final String owner, String t, String sort,
String word, String f, String aggs, String location, String nested,
String filter) {
Expand Down Expand Up @@ -217,7 +220,7 @@ public static Promise<Result> query(final String q, final String agent,
Logger.debug("Not cached: {}, will cache for one hour", cacheId);
QueryBuilder queryBuilder = new Queries.Builder().q(q).agent(agent)
.name(name).subject(subject).id(id).publisher(publisher).issued(issued)
.medium(medium).t(t).owner(owner).nested(nested).location(location)
.medium(medium).t(t).owner(owner).nested(nested).location(location).collection(collection)
.filter(filter).word(word).build();
String sortBy =
responseFormat.equals(Accept.Format.RSS.queryParamString) ? "newest"
Expand All @@ -226,7 +229,7 @@ public static Promise<Result> query(final String q, final String agent,
.size(size).sort(sortBy).aggs(aggregations).build();

Promise<Result> result =
createResult(q, agent, name, subject, id, publisher, issued, medium,
createResult(q, agent, name, subject, id, publisher, issued, medium, collection,
from, size, owner, t, sort, word, nested, responseFormat, index);
cacheOnRedeem(cacheId, result, ONE_HOUR);

Expand Down Expand Up @@ -273,7 +276,7 @@ private static Promise<Result> resultOrError(final String q,
private static Promise<Result> createResult(final String q,
final String agent, final String name, final String subject,
final String id, final String publisher, final String issued,
final String medium, final int from, final int size, final String owner,
final String medium, final String collection, final int from, final int size, final String owner,
String t, String sort, String word, String nested, String responseFormat,
Search index) {
Promise<Result> result =
Expand All @@ -286,7 +289,7 @@ private static Promise<Result> createResult(final String q,
switch (Format.of(responseFormat)) {
case HTML:
return ok(query.render(s, q, agent, name, subject, id,
publisher, issued, medium, from, size,
publisher, issued, medium, collection, from, size,
queryResources.getTotal(), owner, t, sort, word));
case RSS:
String[] segments = request().uri().split("/");
Expand Down Expand Up @@ -379,7 +382,7 @@ private static Status withCallback(final JsonNode json) {

static String toSuggestions(JsonNode json, String labelFields) {
Stream<String> defaultFields =
Stream.of("title", "contribution", "medium", "startDate-endDate");
Stream.of("title", "contribution", "medium", "collection", "startDate-endDate");
String fields = labelFields.equals("suggest")
? defaultFields.collect(Collectors.joining(",")) : labelFields;
Stream<JsonNode> documents = Lists.newArrayList(json.elements()).stream();
Expand Down Expand Up @@ -670,6 +673,7 @@ private static void uncache(List<String> ids) {
* @param publisher Query for the resource publisher
* @param issued Query for the resource issued year
* @param medium Query for the resource medium
* @param collection Query for the resource collection *
* @param from The page start (offset of page of resource to return)
* @param size The page size (size of page of resource to return)
* @param owner Owner filter for resource queries
Expand All @@ -683,12 +687,12 @@ private static void uncache(List<String> ids) {
* @return The search results
*/
public static Promise<Result> facets(String q, String agent, String name,
String subject, String id, String publisher, String issued, String medium,
String subject, String id, String publisher, String issued, String medium, String collection,
int from, int size, String owner, String t, String field, String sort,
String word, String location, String nested, String filter) {

String key = String.format("facets.%s.%s.%s.%s.%s.%s.%s.%s.%s.%s.%s.%s.%s",
field, q, agent, name, id, publisher, word, subject, issued, medium,
field, q, agent, name, id, publisher, word, subject, issued, medium, collection,
owner, t, nested);
Result cachedResult = (Result) Cache.get(key);
if (cachedResult != null) {
Expand Down Expand Up @@ -719,9 +723,9 @@ public static Promise<Result> facets(String q, String agent, String name,
String t1 = p1.getLeft().get("key").asText();
String t2 = p2.getLeft().get("key").asText();
boolean t1Current =
current(subject, agent, medium, owner, t, field, t1, location);
current(subject, agent, medium, collection, owner, t, field, t1, location);
boolean t2Current =
current(subject, agent, medium, owner, t, field, t2, location);
current(subject, agent, medium, collection, owner, t, field, t2, location);
if (t1Current == t2Current) {
if (!field.equals(ISSUED_FIELD)) {
Integer c1 = p1.getLeft().get("doc_count").asInt();
Expand All @@ -742,6 +746,9 @@ public static Promise<Result> facets(String q, String agent, String name,
String mediumQuery = !field.equals(MEDIUM_FIELD) //
? medium
: queryParam(medium, term);
String collectionQuery = !field.equals(COLLECTION_AGGREGATION) //
? collection
: queryParam(collection, term);
String typeQuery = !field.equals(TYPE_FIELD) //
? t
: queryParam(t, term);
Expand All @@ -762,10 +769,10 @@ public static Promise<Result> facets(String q, String agent, String name,
: queryParam(location, term);

boolean current =
current(subject, agent, medium, owner, t, field, term, location);
current(subject, agent, medium, collection, owner, t, field, term, location);

String routeUrl = routes.Application.query(q, agentQuery, name,
subjectQuery, id, publisher, issuedQuery, mediumQuery, from, size,
subjectQuery, id, publisher, issuedQuery, mediumQuery, collectionQuery, from, size,
ownerQuery, typeQuery, sort(sort, subjectQuery), word, null, field,
locationQuery, nested, filter).url();

Expand All @@ -780,7 +787,7 @@ ownerQuery, typeQuery, sort(sort, subjectQuery), word, null, field,
};

Promise<Result> promise =
query(q, agent, name, subject, id, publisher, issued, medium, from,
query(q, agent, name, subject, id, publisher, issued, medium, collection, from,
size, owner, t, sort, word, "json", field, location, nested, filter)
.map(result -> {
JsonNode json = Json.parse(Helpers.contentAsString(result))
Expand All @@ -791,7 +798,7 @@ ownerQuery, typeQuery, sort(sort, subjectQuery), word, null, field,
String labelKey = String.format(
"facets-labels.%s.%s.%s.%s.%s.%s.%s.%s.%s.%s.%s.%s",
field, q, agent, name, id, publisher, word, subject,
issued, medium,
issued, medium, collection,
field.equals(OWNER_AGGREGATION) ? "" : owner, t);
@SuppressWarnings("unchecked")
List<Pair<JsonNode, String>> labelledFacets =
Expand All @@ -812,9 +819,10 @@ private static String sort(String sort, String subjectQuery) {
return subjectQuery.contains(",") ? "" /* relevance */ : sort;
}

private static boolean current(String subject, String agent, String medium,
private static boolean current(String subject, String agent, String medium, String collection,
String owner, String t, String field, String term, String location) {
return field.equals(MEDIUM_FIELD) && contains(medium, term)
|| field.equals(COLLECTION_AGGREGATION) && contains(collection, term)
|| field.equals(TYPE_FIELD) && contains(t, term)
|| field.equals(OWNER_AGGREGATION) && contains(owner, term)
|| field.equals(SUBJECT_FIELD) && contains(subject, term)
Expand Down
3 changes: 2 additions & 1 deletion web/app/controllers/resources/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static controllers.resources.Application.AGENT_FIELD;
import static controllers.resources.Application.ISSUED_FIELD;
import static controllers.resources.Application.MEDIUM_FIELD;
import static controllers.resources.Application.COLLECTION_AGGREGATION;
import static controllers.resources.Application.OWNER_AGGREGATION;
import static controllers.resources.Application.SUBJECT_FIELD;
import static controllers.resources.Application.TOPIC_AGGREGATION;
Expand Down Expand Up @@ -119,7 +120,7 @@ public Builder() {}
* The values supported for the `aggregations` query parameter.
*/
public static final List<String> SUPPORTED_AGGREGATIONS = Arrays.asList(
ISSUED_FIELD, SUBJECT_FIELD, TYPE_FIELD, MEDIUM_FIELD, OWNER_AGGREGATION,
ISSUED_FIELD, SUBJECT_FIELD, TYPE_FIELD, MEDIUM_FIELD, COLLECTION_AGGREGATION, OWNER_AGGREGATION,
AGENT_FIELD, SPATIAL_LABEL_FIELD, SPATIAL_GEO_FIELD, SPATIAL_ID_FIELD,
SUBJECT_ID_FIELD, TOPIC_AGGREGATION);

Expand Down
1 change: 1 addition & 0 deletions web/app/views/tags/facets.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,5 @@ <h5>@facetToggle("issued-facet-all"){Erscheinungsjahr} @facetLabel(issued, issue
<div class="row facet"><div class="col-md-12">@facets("Medientypen", Application.MEDIUM_FIELD, medium, "dropup")</div></div>
<div class="row facet"><div class="col-md-12">@facets("Publikationstypen", Application.TYPE_FIELD, t, "dropup")</div></div>
<div class="row facet"><div class="col-md-12">@facets("Bestand in Bibliotheken", Application.OWNER_AGGREGATION, owner, "dropup")</div></div>
<div class="row facet"><div class="col-md-12">@facets("Collections", Application.COLLECTION_AGGREGATION, collection, "dropup")</div></div>
</div>
Loading