Skip to content

Instantly share code, notes, and snippets.

@phillipuniverse
Created June 2, 2011 17:31
Show Gist options
  • Save phillipuniverse/1004865 to your computer and use it in GitHub Desktop.
Save phillipuniverse/1004865 to your computer and use it in GitHub Desktop.
Andre Compass Example
@Override
public List<PBProductTire> findTiresForSize(String width, String ratio, String diameter, String passOrLightTruck, String ratingOrRange) {
String query = "alias:PBProductTire AND tireWidth:" + width + " AND tireRatio:" + ratio + " AND tireDiameter:" + diameter;
if (passOrLightTruck.equals("LT")) {
query += " AND tireType:LT";
} else {
query += " AND NOT tireType:LT";
}
CompassSearchSession session = compass.openSearchSession();
CompassDetachedHits hits = session.find(query).detach();
session.close();
List<PBProductTire> results = new ArrayList<PBProductTire>(hits.length());
for (int i = 0; i < hits.length(); i++) {
PBProductTire tire = (PBProductTire) catalogService.findProductById(((PBProductTire) hits.data(i)).getId());
if ((passOrLightTruck.equals("LT") && tireLogicService.meetsLoadRange(tire, ratingOrRange))
|| (tireLogicService.meetsSpeedRating(tire, ratingOrRange))) {
results.add(tire);
}
}
return results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment