search.go raw

   1  /**
   2   * Copyright 2016-2024 IBM Corp.
   3   *
   4   * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
   5   * the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
   6   *
   7   * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
   8   * on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   9   * See the License for the specific language governing permissions and limitations under the License.
  10   */
  11  
  12  // AUTOMATICALLY GENERATED CODE - DO NOT MODIFY
  13  
  14  package services
  15  
  16  import (
  17  	"fmt"
  18  	"strings"
  19  
  20  	"github.com/softlayer/softlayer-go/datatypes"
  21  	"github.com/softlayer/softlayer-go/session"
  22  	"github.com/softlayer/softlayer-go/sl"
  23  )
  24  
  25  // no documentation yet
  26  type Search struct {
  27  	Session session.SLSession
  28  	Options sl.Options
  29  }
  30  
  31  // GetSearchService returns an instance of the Search SoftLayer service
  32  func GetSearchService(sess session.SLSession) Search {
  33  	return Search{Session: sess}
  34  }
  35  
  36  func (r Search) Id(id int) Search {
  37  	r.Options.Id = &id
  38  	return r
  39  }
  40  
  41  func (r Search) Mask(mask string) Search {
  42  	if !strings.HasPrefix(mask, "mask[") && (strings.Contains(mask, "[") || strings.Contains(mask, ",")) {
  43  		mask = fmt.Sprintf("mask[%s]", mask)
  44  	}
  45  
  46  	r.Options.Mask = mask
  47  	return r
  48  }
  49  
  50  func (r Search) Filter(filter string) Search {
  51  	r.Options.Filter = filter
  52  	return r
  53  }
  54  
  55  func (r Search) Limit(limit int) Search {
  56  	r.Options.Limit = &limit
  57  	return r
  58  }
  59  
  60  func (r Search) Offset(offset int) Search {
  61  	r.Options.Offset = &offset
  62  	return r
  63  }
  64  
  65  // This method allows for searching for SoftLayer resources by simple terms and operators.  Fields that are used for searching will be available at sldn.softlayer.com. It returns a collection or array of [[SoftLayer_Container_Search_Result]] objects that have search metadata for each result and the resulting resource found.
  66  //
  67  // The advancedSearch() method recognizes the special <code>_objectType:</code></b> quantifier in search strings.  See the documentation for the [[SoftLayer_Search/search]] method on how to restrict searches using object types.
  68  //
  69  // The advancedSearch() method recognizes [[SoftLayer_Container_Search_ObjectType_Property]], which can also be used to limit searches.  Example:
  70  //
  71  // <code>_objectType:Type_1 propertyA:</code><i><code>value</code></i>
  72  //
  73  // A search string can specify multiple properties, separated with spaces. Example:
  74  //
  75  // <code>_objectType:Type_1 propertyA:</code><i><code>value</code></i> <code>propertyB:</code><i><code>value</code></i>
  76  //
  77  // A collection of available object types and their properties can be retrieved by calling the [[SoftLayer_Search/getObjectTypes]] method.
  78  //
  79  // #### Exact Match on Text Fields
  80  // To enforce an exact match on text fields, encapsulate the term in double quotes. For example, given a set of device host names:
  81  //
  82  // <ul> <li>baremetal-a</li> <li>baremetal-b</li> <li>a-virtual-guest</li> <li>b-virtual-guest</li> <li>edge-router</li> </ul>
  83  //
  84  // An exact search (double-quote) for "baremetal-a" will return only the exact match of <u>baremetal-a</u>.
  85  //
  86  // A fuzzy search (no double-quote) for baremetal-a will return <u>baremetal</u>-<u>a</u>, <u>baremetal</u>-b, <u>a</u>-virtu<u>a</u>l-guest, b-virtu<u>a</u>l-guest but will omit edge-router.
  87  func (r Search) AdvancedSearch(searchString *string) (resp []datatypes.Container_Search_Result, err error) {
  88  	params := []interface{}{
  89  		searchString,
  90  	}
  91  	err = r.Session.DoRequest("SoftLayer_Search", "advancedSearch", params, &r.Options, &resp)
  92  	return
  93  }
  94  
  95  // This method returns a collection of [[SoftLayer_Container_Search_ObjectType]] containers that specify which indexed object types and properties are exposed for the current user.  These object types can be used to discover searchable data and to create or validate object index search strings.
  96  //
  97  // Refer to the [[SoftLayer_Search/search]] and [[SoftLayer_Search/advancedSearch]] methods for information on using object types and properties in search strings.
  98  func (r Search) GetObjectTypes() (resp []datatypes.Container_Search_ObjectType, err error) {
  99  	err = r.Session.DoRequest("SoftLayer_Search", "getObjectTypes", nil, &r.Options, &resp)
 100  	return
 101  }
 102  
 103  // This method allows for searching for SoftLayer resources by simple phrase. It returns a collection or array of [[SoftLayer_Container_Search_Result]] objects that have search metadata for each result and the resulting resource found.
 104  //
 105  // This method recognizes the special <b><code>_objectType:</code></b> quantifier in search strings.  This quantifier can be used to restrict a search to specific object types.  Example usage:
 106  //
 107  // <code>_objectType:Type_1 </code><i><code>(other search terms...)</code></i>
 108  //
 109  // A search string can specify multiple object types, separated by commas (no spaces are permitted between the type names).  Example:
 110  //
 111  // <code>_objectType:Type_1,Type_2,Type_3 </code><i><code>(other search terms...)</code></i>
 112  //
 113  // If the list of object types is prefixed with a hyphen or minus sign (-), then the specified types are excluded from the search.  Example:
 114  //
 115  // <code>_objectType:-Type_4,Type_5 </code><i><code>(other search terms...)</code></i>
 116  //
 117  // A collection of available object types can be retrieved by calling the [[SoftLayer_Search/getObjectTypes]] method.
 118  //
 119  // #### Exact Match on Text Fields
 120  // To enforce an exact match on text fields, encapsulate the term in double quotes. For example, given a set of device host names:
 121  //
 122  // <ul> <li>baremetal-a</li> <li>baremetal-b</li> <li>a-virtual-guest</li> <li>b-virtual-guest</li> <li>edge-router</li> </ul>
 123  //
 124  // An exact search (double-quote) for "baremetal-a" will return only the exact match of <u>baremetal-a</u>.
 125  //
 126  // A fuzzy search (no double-quote) for baremetal-a will return <u>baremetal</u>-<u>a</u>, <u>baremetal</u>-b, <u>a</u>-virtu<u>a</u>l-guest, b-virtu<u>a</u>l-guest but will omit edge-router.
 127  func (r Search) Search(searchString *string) (resp []datatypes.Container_Search_Result, err error) {
 128  	params := []interface{}{
 129  		searchString,
 130  	}
 131  	err = r.Session.DoRequest("SoftLayer_Search", "search", params, &r.Options, &resp)
 132  	return
 133  }
 134