diff --git a/models/Document.cfc b/models/Document.cfc index effa401..5097836 100644 --- a/models/Document.cfc +++ b/models/Document.cfc @@ -284,8 +284,8 @@ component accessors="true" { if ( arguments.includeKey && !isNull( variables.id ) ) { documentObject[ "_id" ] = variables.id; } - if ( arguments.includeFields ){ - structAppend(documentObject, getFields(), true ); + if ( arguments.includeFields ) { + structAppend( documentObject, getFields(), true ); } return documentObject; diff --git a/models/SearchBuilder.cfc b/models/SearchBuilder.cfc index 833883e..8dfe229 100644 --- a/models/SearchBuilder.cfc +++ b/models/SearchBuilder.cfc @@ -52,14 +52,14 @@ component accessors="true" { /** * Property containing elasticsearch "script_fields" definition for runtime scripted fields - * + * * https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#script-fields */ property name="scriptFields" type="struct"; /** * Property containing "fields" array of fields to return for each hit - * + * * https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html */ property name="fields" type="array"; @@ -123,7 +123,7 @@ component accessors="true" { variables.params = []; variables.body = {}; - variables.size = 25; + variables.size = 25; variables.from = 0; variables.preflight = true; @@ -172,9 +172,9 @@ component accessors="true" { /** * Backwards compatible setter for max result size - * + * * @deprecated - * + * * @value Max number of records to retrieve. */ SearchBuilder function setMaxRows( required numeric value ){ @@ -183,9 +183,9 @@ component accessors="true" { } /** * Backwards compatible setter for result start offset - * + * * @deprecated - * + * * @value Starting document offset. */ SearchBuilder function setStartRow( required numeric value ){ @@ -876,16 +876,16 @@ component accessors="true" { /** * Generic setter for any/all request properties. - * + * * For example, `set( "size", 100 )` or `set( "min_score" : 1 )`. - * + * * Example https://www.elastic.co/guide/en/elasticsearch/reference/8.7/search-search.html#search-search-api-request-body * * @name the name of the parameter to set. * @value the value of the parameter */ SearchBuilder function set( required string name, required any value ){ - if( variables.keyExists( arguments.name ) ){ + if ( variables.keyExists( arguments.name ) ) { variables[ arguments.name ] = arguments.value; } else { variables.body[ arguments.name ] = arguments.value; @@ -896,7 +896,7 @@ component accessors="true" { /** * Adds a body parameter to the request (such as filtering by min_score, forcing a relevance score return, etc.) - * + * * Example https://www.elastic.co/guide/en/elasticsearch/reference/8.7/search-search.html#search-search-api-request-body * * @name the name of the body parameter to set @@ -1290,8 +1290,12 @@ component accessors="true" { * @script Script to use. `{ "script" : { "lang": "painless", "source" : } }` * @source Which _source values to include in the response. `true` for all, `false` for none, or a wildcard-capable string: `source = "author.*"` */ - public SearchBuilder function addScriptField( required string name, struct script, any source = true ){ - if ( isNull( variables.scriptFields ) ){ + public SearchBuilder function addScriptField( + required string name, + struct script, + any source = true + ){ + if ( isNull( variables.scriptFields ) ) { variables.scriptFields = {}; } variables.scriptFields[ arguments.name ] = arguments.script; @@ -1301,23 +1305,24 @@ component accessors="true" { /** * Append a field name or object in the list of fields to return. - * + * * Especially useful for runtime fields. - * + * * Example: * ``` * addField( { "field": "@timestamp", "format": "epoch_millis" } ) * ``` - * + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime-retrieving-fields.html#runtime-search-dayofweek * * @value string|struct Field name to retrieve OR struct config */ public SearchBuilder function addField( required any value ){ - if ( isNull( variables.fields ) ){ + if ( isNull( variables.fields ) ) { variables.fields = []; } variables.fields.append( arguments.value ); return this; } + } diff --git a/models/SearchResult.cfc b/models/SearchResult.cfc index e73bd4a..6902bcb 100644 --- a/models/SearchResult.cfc +++ b/models/SearchResult.cfc @@ -144,7 +144,7 @@ component accessors="true" { for ( var hit in arguments.hits ) { var documentSource = hit.keyExists( "_source" ) ? hit[ "_source" ] : {}; - var doc = newDocument().populate( documentSource ); + var doc = newDocument().populate( documentSource ); doc.setIndex( hit[ "_index" ] ); diff --git a/models/io/HyperClient.cfc b/models/io/HyperClient.cfc index c6f774c..ed1ac9a 100644 --- a/models/io/HyperClient.cfc +++ b/models/io/HyperClient.cfc @@ -1681,24 +1681,34 @@ component accessors="true" threadSafe singleton { * * @indexName string|array Index name or array of index names to query on * @field string|struct If string, field name to query. Otherwise, a struct of query options where only "field" is required. - * + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/8.7/search-terms-enum.html */ - function getTermsEnum( required indexName, required any field, any match, numeric size = 10, boolean caseInsensitive = true ){ - if ( isArray( arguments.indexName ) ){ arguments.indexName = arrayToList( arguments.indexName ); } + function getTermsEnum( + required indexName, + required any field, + any match, + numeric size = 10, + boolean caseInsensitive = true + ){ + if ( isArray( arguments.indexName ) ) { + arguments.indexName = arrayToList( arguments.indexName ); + } var termsRequest = variables.nodePool.newRequest( "/#arguments.indexName#/_terms_enum", "post" ); var opts = { - "size" : arguments.size, - "case_insensitive": arguments.caseInsensitive, - "field" : !isNull( arguments.match ) ? arguments.match : javaCast( "null", 0 ) + "size" : arguments.size, + "case_insensitive" : arguments.caseInsensitive, + "field" : !isNull( arguments.match ) ? arguments.match : javacast( "null", 0 ) }; - if ( !isSimpleValue( arguments.field ) ){ opts = arguments.field; } + if ( !isSimpleValue( arguments.field ) ) { + opts = arguments.field; + } return termsRequest - .setBody( opts ) - .send() - .json(); + .setBody( opts ) + .send() + .json(); } } diff --git a/models/util/Util.cfc b/models/util/Util.cfc index 3d2b034..1c50d42 100644 --- a/models/util/Util.cfc +++ b/models/util/Util.cfc @@ -198,17 +198,28 @@ component accessors="true" singleton { * @entry The entry struct * @key The key to extract the message from */ - function processHTMLFormattedMessages( required struct entry, string key="message" ){ + function processHTMLFormattedMessages( required struct entry, string key = "message" ){ // Lucee will sometimes transmit the error template as the exception message - var htmlMessageRegex = 'Message<\/td>\s*(.*?)<\/td>'; - if( reFindNoCase( htmlMessageRegex, arguments.entry[ arguments.key ], 1, false ) ){ - var match = refindNoCase( htmlMessageRegex, arguments.entry[ arguments.key ], 1, true ).match; - if( match.len() >= 2 ){ - if( arguments.entry.keyExists( "error" ) ){ + var htmlMessageRegex = "Message<\/td>\s*(.*?)<\/td>"; + if ( + reFindNoCase( + htmlMessageRegex, + arguments.entry[ arguments.key ], + 1, + false + ) + ) { + var match = reFindNoCase( + htmlMessageRegex, + arguments.entry[ arguments.key ], + 1, + true + ).match; + if ( match.len() >= 2 ) { + if ( arguments.entry.keyExists( "error" ) ) { arguments.entry.error[ "extrainfo" ] = arguments.entry[ arguments.key ]; } - arguments.entry[ arguments.key ] = match[2]; - + arguments.entry[ arguments.key ] = match[ 2 ]; } } }