@@ -370,13 +370,12 @@ component {
370370 };
371371 }
372372
373- public struct function search (string domain , string typename , string rawQuery , string queryParser = " simple" , string rawFilter , array conditions , array filters , numeric maxrows = 10 , numeric page = 1 , boolean log = true ) {
373+ public struct function search (string domain , string typename , string rawQuery , string queryParser = " simple" , string rawFilter , string rawFacets , array conditions , array filters , struct facets = {} , numeric maxrows = 10 , numeric page = 1 , boolean log = true ) {
374374 var csdClient = " " ;
375375 var searchRequest = createobject (" java" ," com.amazonaws.services.cloudsearchdomain.model.SearchRequest" ).init ();
376376 var searchResponse = {};
377377 var hits = {};
378378 var hit = {};
379- var facets = {};
380379 var buckets = {};
381380 var bucket = {};
382381 var stIndexFields = {};
@@ -388,6 +387,7 @@ component {
388387 var op = " " ;
389388 var stResult = {};
390389 var st = {};
390+ var facetResult = {};
391391
392392 if (arguments .log ){
393393 arguments .log = false ;
@@ -463,11 +463,37 @@ component {
463463 }
464464 }
465465
466+ // create facet config
467+ if (not structKeyExists (arguments ," rawFacets" )){
468+ if (not structKeyExists (arguments ," facets" )){
469+ arguments .facets = {};
470+ }
471+
472+ st = {};
473+ for (key in arguments .facets ) {
474+ for (key S in stIndexFields ) {
475+ if (stIndexFields [key S ].property eq key ) {
476+ st [stIndexFields [key S ].field ] = arguments .facets [key ];
477+ }
478+ }
479+ }
480+
481+ if (structCount (st )){
482+ arguments .rawFacets = serializeJSON (st );
483+ }
484+ else {
485+ arguments .rawFacets = " " ;
486+ }
487+ }
488+
466489 searchRequest .setQueryParser (arguments .queryParser );
467490 searchRequest .setQuery (arguments .rawQuery );
468- if (structKeyExists ( arguments , " rawFilter " ) and len (arguments .rawFilter )){
491+ if (len (arguments .rawFilter )){
469492 searchRequest .setFilterQuery (arguments .rawFilter );
470493 }
494+ if (len (arguments .rawFacets )){
495+ searchRequest .setFacet (arguments .rawFacets );
496+ }
471497 searchRequest .setStart (arguments .maxrows * (arguments .page - 1 ));
472498 searchRequest .setSize (arguments .maxrows );
473499
@@ -478,12 +504,12 @@ component {
478504 throw (message = e .message , detail = serializeJSON (duplicate (arguments )));
479505 }
480506 hits = searchResponse .getHits ();
481- facets = searchResponse .getFacets ();
507+ facetResult = searchResponse .getFacets ();
482508
483509 stResult [" time" ] = searchResponse .getStatus ().getTimems ();
484510 stResult [" cursor" ] = hits .getCursor ();
485511 stResult [" items" ] = querynew (" objectid,typename,highlights" );
486- stResult [" facets " ] = querynew ( " field,value,count " , " varchar,varchar,int " ) ;
512+ stResult [" stFacets " ] = {} ;
487513 if (structKeyExists (arguments ," conditions" )){
488514 stResult [" conditions" ] = arguments .conditions ;
489515 }
@@ -493,6 +519,10 @@ component {
493519 stResult [" filters" ] = arguments .filters ;
494520 }
495521 stResult [" rawFilter" ] = arguments .rawFilter ;
522+ if (structKeyExists (arguments ," facets" )){
523+ stResult [" facets" ] = arguments .facets ;
524+ }
525+ stResult [" rawFacets" ] = arguments .rawFacets ;
496526 stResult [" recordcount" ] = hits .getFound ();
497527 stResult [" page" ] = arguments .page ;
498528 stResult [" maxrows" ] = arguments .maxrows ;
@@ -504,14 +534,12 @@ component {
504534 querySetCell (stResult .items ," highlights" ,serializeJSON (duplicate (hit .getHighlights ())));
505535 }
506536
507- for (key in facets ){
508- buckets = facets [key ].getBuckets ;
537+ for (key in facetResult ){
538+ buckets = facetResult [key ].getBuckets ();
539+ stResult [" stFacets" ][stIndexFields [key ].property ] = [];
509540
510541 for (bucket in buckets ){
511- queryAddRow (stResult .facets );
512- querySetCell (stResult .facets ," field" ,key );
513- querySetCell (stResult .facets ," value" ,bucket .getValue ());
514- querySetCell (stResult .facets ," count" ,bucket .getCount ());
542+ arrayappend (stResult [" stFacets" ][stIndexFields [key ].property ], { " value" = bucket .getValue (), " count" = bucket .getCount () });
515543 }
516544 }
517545
0 commit comments