res.setHits(browseHits);
return res;
}
public static BrowseRequest convert(BrowseRequestBPO.Request req,QueryParser qparser) throws ParseException{
BrowseRequest breq = new BrowseRequest();
String query = req.getQuery();
if (qparser!=null && query!=null && query.length() > 0){
try{
Query q = qparser.parse(query);
breq.setQuery(q);
}
catch(Exception e){
throw new ParseException(e.getMessage());
}
}
breq.setOffset(req.getOffset());
breq.setCount(req.getCount());
int i = 0;
List<BrowseRequestBPO.Sort> sortList = req.getSortList();
SortField[] sortFields = new SortField[sortList == null ? 0 : sortList.size()];
for (BrowseRequestBPO.Sort s : sortList){
String fieldname = s.getField();
if (fieldname!=null && fieldname.length() == 0){
fieldname=null;
}
SortField sf = new SortField(fieldname,s.getType(),s.getReverse());
sortFields[i++] = sf;
}
if (sortFields.length > 0){
breq.setSort(sortFields);
}
List<BrowseRequestBPO.FacetSpec> fspecList = req.getFacetSpecsList();
for (BrowseRequestBPO.FacetSpec fspec : fspecList){
FacetSpec facetSpec = new FacetSpec();
facetSpec.setExpandSelection(fspec.getExpand());
facetSpec.setMaxCount(fspec.getMax());
facetSpec.setMinHitCount(fspec.getMinCount());
BrowseRequestBPO.FacetSpec.SortSpec fsort = fspec.getOrderBy();
if (fsort == BrowseRequestBPO.FacetSpec.SortSpec.HitsDesc)
{
facetSpec.setOrderBy(FacetSortSpec.OrderHitsDesc);
}
else
{
facetSpec.setOrderBy(FacetSortSpec.OrderValueAsc);
}
breq.setFacetSpec(fspec.getName(), facetSpec);
}
List<BrowseRequestBPO.Selection> selList = req.getSelectionsList();
for (BrowseRequestBPO.Selection sel : selList){
BrowseSelection bsel = null;
List<String> vals = sel.getValuesList();
if (vals!=null)
{
if (bsel==null)
{
bsel = new BrowseSelection(sel.getName());
}
bsel.setValues(vals.toArray(new String[vals.size()]));
}
vals = sel.getNotValuesList();
if (vals!=null)
{
if (bsel==null)
{
bsel = new BrowseSelection(sel.getName());
}
bsel.setNotValues(vals.toArray(new String[vals.size()]));
}
if (bsel!= null){
BrowseRequestBPO.Selection.Operation operation = sel.getOp();
if (operation == BrowseRequestBPO.Selection.Operation.OR){
bsel.setSelectionOperation(ValueOperation.ValueOperationOr);
}
else{
bsel.setSelectionOperation(ValueOperation.ValueOperationAnd);
}
List<BrowseRequestBPO.Property> props = sel.getPropsList();
if (props!=null)
{
for (BrowseRequestBPO.Property prop : props){
bsel.setSelectionProperty(prop.getKey(), prop.getVal());
}
}
breq.addSelection(bsel);
}
}
return breq;
}