Commit 473f45e1 authored by Rob Tomsick's avatar Rob Tomsick

Add more barcode-based search cleverness.

parent b0694c6a
......@@ -329,11 +329,6 @@ public class SearchController
limit = service.resultLimit() < limit ? service.resultLimit() : limit;
if (! service.dictionary().supports(DictionaryCapabilities.BARCODES))
{
return ResponseEntity.noContent().build();
}
List<Product> results = new ArrayList<>();
/* try to figure out what barcode it is... */
......@@ -343,8 +338,10 @@ public class SearchController
{
return ResponseEntity.ok(Collections.emptyList());
}
results.addAll(service.findByBarcode(barcode, limit));
if (service.dictionary().supports(DictionaryCapabilities.BARCODES))
{
results.addAll(service.findByBarcode(barcode, limit));
}
/* If we have a UPCA, see if we can get a UPN out of it and search by
* NDC that way.
......@@ -353,11 +350,18 @@ public class SearchController
&& barcode instanceof UPCA
&& results.size() < limit)
{
final int[] upn = ((UPCA) barcode).toUPN();
if (upn != null)
/* handle UPN if available */
if (barcode instanceof UPCA)
{
NDC ndc = NDC.create(upn);
results.addAll(service.findByNDC(ndc, limit - results.size()));
NDC[] ndcs = NDC.possibleNDCs((UPCA) barcode);
for (NDC n : ndcs)
{
int max = results.size() - limit;
max = max < 0 ? limit : max;
results.addAll(service.findByNDC(n, max));
}
}
}
......@@ -511,14 +515,14 @@ public class SearchController
/* handle UPN if available */
if (barcode instanceof UPCA)
{
int[] upn = ((UPCA) barcode).toUPN();
NDC[] ndcs = NDC.possibleNDCs((UPCA) barcode);
if (upn != null)
for (NDC n : ndcs)
{
ndc = NDC.create(upn);
max = results.size() - limit;
max = max < 0 ? limit : max;
results.addAll(service.findByNDC(ndc, max)
results.addAll(service.findByNDC(n, max)
.stream()
.map(p -> Result.of(p, p.displayName()))
.collect(Collectors.toList()));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment