Skip to content

Commit

Permalink
cfformat updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jclausen committed Apr 24, 2023
1 parent 0b2fe3b commit 0532861
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 38 deletions.
4 changes: 2 additions & 2 deletions models/Document.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
39 changes: 22 additions & 17 deletions models/SearchBuilder.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -123,7 +123,7 @@ component accessors="true" {
variables.params = [];
variables.body = {};

variables.size = 25;
variables.size = 25;
variables.from = 0;

variables.preflight = true;
Expand Down Expand Up @@ -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 ){
Expand All @@ -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 ){
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

}
2 changes: 1 addition & 1 deletion models/SearchResult.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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" ] );

Expand Down
30 changes: 20 additions & 10 deletions models/io/HyperClient.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
27 changes: 19 additions & 8 deletions models/util/Util.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<td class="label">Message<\/td>\s*<td>(.*?)<\/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 = "<td class=""label"">Message<\/td>\s*<td>(.*?)<\/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 ];
}
}
}
Expand Down

0 comments on commit 0532861

Please sign in to comment.