Skip to content

Commit 17ee7fb

Browse files
committed
Added additional comments and updated existing ones to explain the convoluted behavior of the get neighbors query
1 parent 66c78b5 commit 17ee7fb

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

access-common/src/main/java/edu/unc/lib/dl/ui/service/SolrQueryLayerService.java

+12-13
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,9 @@ public List<BriefObjectMetadataBean> getParentCollectionValues(FacetFieldObject
288288
}
289289

290290
/**
291-
* Retrieves a list of the nearest windowSize neighbors within the nearest parent collection or folder around the
292-
* item metadata, based on the order field of the item. The first windowSize - 1 neighbors are retrieved to each side
293-
* of the item, and trimmed so that there are always windowSize - 1 neighbors surrounding the item if possible. If no
294-
* order field is available, a list of arbitrary windowSize neighbors is returned.
291+
* Retrieves a list of the closest windowSize neighbors within the parent container of the specified object,
292+
* using the default sort order. The first windowSize / 2 - 1 neighbors are retrieved to each side
293+
* of the item, and trimmed so that there are always windowSize - 1 neighbors surrounding the item if possible.
295294
*
296295
* @param metadata
297296
* Record which the window pivots around.
@@ -305,45 +304,43 @@ public List<BriefObjectMetadataBean> getNeighboringItems(BriefObjectMetadataBean
305304
AccessGroupSet accessGroups) {
306305

307306
// Get the common access restriction clause (starts with "AND ...")
308-
309307
StringBuilder accessRestrictionClause = new StringBuilder();
310308

311309
try {
312310
addAccessRestrictions(accessRestrictionClause, accessGroups);
313311
} catch (AccessRestrictionException e) {
314312
// If the user doesn't have any access groups, they don't have access to anything, return null.
315-
LOG.error(e.getMessage());
313+
LOG.error("Attempted to get neighboring items without creditentials", e);
316314
return null;
317315
}
318316

319-
// Prepare the common query object, including a filter for resource type and the
320-
// facet which selects only the item's siblings.
321-
317+
// Restrict query to files/aggregates and objects within the same parent
322318
SolrQuery solrQuery = new SolrQuery();
319+
solrQuery.setQuery("*:*" + accessRestrictionClause);
323320

324321
solrQuery.setFacet(true);
325322
solrQuery.addFilterQuery(solrSettings.getFieldName(SearchFieldKeys.RESOURCE_TYPE.name()) + ":File "
326323
+ solrSettings.getFieldName(SearchFieldKeys.RESOURCE_TYPE.name()) + ":Aggregate");
327324

328325
CutoffFacet ancestorPath = null;
329-
330326
if (metadata.getResourceType().equals(searchSettings.resourceTypeFile)
331327
|| metadata.getResourceType().equals(searchSettings.resourceTypeAggregate)) {
332328
ancestorPath = metadata.getAncestorPathFacet();
333329
} else {
334330
ancestorPath = metadata.getPath();
335331
}
336-
337332
if (ancestorPath != null) {
338333
// We want only objects at the same level of the hierarchy
339334
ancestorPath.setCutoff(ancestorPath.getHighestTier() + 1);
340335

341336
facetFieldUtil.addToSolrQuery(ancestorPath, solrQuery);
342337
}
343338

344-
solrQuery.setQuery("*:*" + accessRestrictionClause);
345-
339+
// Sort neighbors using the default sort
346340
addSort(solrQuery, "default", true);
341+
342+
343+
// Query for ids in this container in groups of NEIGHBOR_SEEK_PAGE_SIZE until we find the offset of the object
347344
solrQuery.setRows(NEIGHBOR_SEEK_PAGE_SIZE);
348345
solrQuery.setFields("id");
349346

@@ -371,6 +368,7 @@ public List<BriefObjectMetadataBean> getNeighboringItems(BriefObjectMetadataBean
371368
return null;
372369
}
373370

371+
// Calculate the starting index for the window, so that object is as close to the middle as possible
374372
long left = start - (windowSize / 2);
375373
long right = start + (windowSize / 2);
376374

@@ -386,6 +384,7 @@ public List<BriefObjectMetadataBean> getNeighboringItems(BriefObjectMetadataBean
386384
}
387385
}
388386

387+
// Query for the windowSize of objects
389388
solrQuery.setFields(new String[0]);
390389
solrQuery.setRows(windowSize);
391390
solrQuery.setStart((int) left);

0 commit comments

Comments
 (0)