@@ -288,10 +288,9 @@ public List<BriefObjectMetadataBean> getParentCollectionValues(FacetFieldObject
288
288
}
289
289
290
290
/**
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.
295
294
*
296
295
* @param metadata
297
296
* Record which the window pivots around.
@@ -305,45 +304,43 @@ public List<BriefObjectMetadataBean> getNeighboringItems(BriefObjectMetadataBean
305
304
AccessGroupSet accessGroups ) {
306
305
307
306
// Get the common access restriction clause (starts with "AND ...")
308
-
309
307
StringBuilder accessRestrictionClause = new StringBuilder ();
310
308
311
309
try {
312
310
addAccessRestrictions (accessRestrictionClause , accessGroups );
313
311
} catch (AccessRestrictionException e ) {
314
312
// 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 );
316
314
return null ;
317
315
}
318
316
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
322
318
SolrQuery solrQuery = new SolrQuery ();
319
+ solrQuery .setQuery ("*:*" + accessRestrictionClause );
323
320
324
321
solrQuery .setFacet (true );
325
322
solrQuery .addFilterQuery (solrSettings .getFieldName (SearchFieldKeys .RESOURCE_TYPE .name ()) + ":File "
326
323
+ solrSettings .getFieldName (SearchFieldKeys .RESOURCE_TYPE .name ()) + ":Aggregate" );
327
324
328
325
CutoffFacet ancestorPath = null ;
329
-
330
326
if (metadata .getResourceType ().equals (searchSettings .resourceTypeFile )
331
327
|| metadata .getResourceType ().equals (searchSettings .resourceTypeAggregate )) {
332
328
ancestorPath = metadata .getAncestorPathFacet ();
333
329
} else {
334
330
ancestorPath = metadata .getPath ();
335
331
}
336
-
337
332
if (ancestorPath != null ) {
338
333
// We want only objects at the same level of the hierarchy
339
334
ancestorPath .setCutoff (ancestorPath .getHighestTier () + 1 );
340
335
341
336
facetFieldUtil .addToSolrQuery (ancestorPath , solrQuery );
342
337
}
343
338
344
- solrQuery .setQuery ("*:*" + accessRestrictionClause );
345
-
339
+ // Sort neighbors using the default sort
346
340
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
347
344
solrQuery .setRows (NEIGHBOR_SEEK_PAGE_SIZE );
348
345
solrQuery .setFields ("id" );
349
346
@@ -371,6 +368,7 @@ public List<BriefObjectMetadataBean> getNeighboringItems(BriefObjectMetadataBean
371
368
return null ;
372
369
}
373
370
371
+ // Calculate the starting index for the window, so that object is as close to the middle as possible
374
372
long left = start - (windowSize / 2 );
375
373
long right = start + (windowSize / 2 );
376
374
@@ -386,6 +384,7 @@ public List<BriefObjectMetadataBean> getNeighboringItems(BriefObjectMetadataBean
386
384
}
387
385
}
388
386
387
+ // Query for the windowSize of objects
389
388
solrQuery .setFields (new String [0 ]);
390
389
solrQuery .setRows (windowSize );
391
390
solrQuery .setStart ((int ) left );
0 commit comments