@@ -370,13 +370,12 @@ component {
370
370
};
371
371
}
372
372
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 ) {
374
374
var csdClient = " " ;
375
375
var searchRequest = createobject (" java" ," com.amazonaws.services.cloudsearchdomain.model.SearchRequest" ).init ();
376
376
var searchResponse = {};
377
377
var hits = {};
378
378
var hit = {};
379
- var facets = {};
380
379
var buckets = {};
381
380
var bucket = {};
382
381
var stIndexFields = {};
@@ -388,6 +387,7 @@ component {
388
387
var op = " " ;
389
388
var stResult = {};
390
389
var st = {};
390
+ var facetResult = {};
391
391
392
392
if (arguments .log ){
393
393
arguments .log = false ;
@@ -463,11 +463,37 @@ component {
463
463
}
464
464
}
465
465
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
+
466
489
searchRequest .setQueryParser (arguments .queryParser );
467
490
searchRequest .setQuery (arguments .rawQuery );
468
- if (structKeyExists ( arguments , " rawFilter " ) and len (arguments .rawFilter )){
491
+ if (len (arguments .rawFilter )){
469
492
searchRequest .setFilterQuery (arguments .rawFilter );
470
493
}
494
+ if (len (arguments .rawFacets )){
495
+ searchRequest .setFacet (arguments .rawFacets );
496
+ }
471
497
searchRequest .setStart (arguments .maxrows * (arguments .page - 1 ));
472
498
searchRequest .setSize (arguments .maxrows );
473
499
@@ -478,12 +504,12 @@ component {
478
504
throw (message = e .message , detail = serializeJSON (duplicate (arguments )));
479
505
}
480
506
hits = searchResponse .getHits ();
481
- facets = searchResponse .getFacets ();
507
+ facetResult = searchResponse .getFacets ();
482
508
483
509
stResult [" time" ] = searchResponse .getStatus ().getTimems ();
484
510
stResult [" cursor" ] = hits .getCursor ();
485
511
stResult [" items" ] = querynew (" objectid,typename,highlights" );
486
- stResult [" facets " ] = querynew ( " field,value,count " , " varchar,varchar,int " ) ;
512
+ stResult [" stFacets " ] = {} ;
487
513
if (structKeyExists (arguments ," conditions" )){
488
514
stResult [" conditions" ] = arguments .conditions ;
489
515
}
@@ -493,6 +519,10 @@ component {
493
519
stResult [" filters" ] = arguments .filters ;
494
520
}
495
521
stResult [" rawFilter" ] = arguments .rawFilter ;
522
+ if (structKeyExists (arguments ," facets" )){
523
+ stResult [" facets" ] = arguments .facets ;
524
+ }
525
+ stResult [" rawFacets" ] = arguments .rawFacets ;
496
526
stResult [" recordcount" ] = hits .getFound ();
497
527
stResult [" page" ] = arguments .page ;
498
528
stResult [" maxrows" ] = arguments .maxrows ;
@@ -504,14 +534,12 @@ component {
504
534
querySetCell (stResult .items ," highlights" ,serializeJSON (duplicate (hit .getHighlights ())));
505
535
}
506
536
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 ] = [];
509
540
510
541
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 () });
515
543
}
516
544
}
517
545
0 commit comments