ArcObjects Library Reference (Carto)  

IMapServer2.Find Method

Returns a collection of Map Server Find Result objects that contain the given search string. If LayerIDs is Nothing/Null or empty, all layers are searched.

[Visual Basic .NET]
Public Function Find ( _
    ByVal mapDesc As IMapDescription, _
    ByVal MapImage As IImageDisplay, _
    ByVal searchString As String, _
    ByVal Contains As Boolean, _
    ByVal searchFields As String, _
    ByVal option As esriFindOption, _
    ByVal layerIds As ILongArray _
) As IMapServerFindResults
[C#]
public IMapServerFindResults Find (
    IMapDescription mapDesc,
    IImageDisplay MapImage,
    string searchString,
    bool Contains,
    string searchFields,
    esriFindOption option,
    ILongArray layerIds
);
[C++]
HRESULT Find(
  IMapDescription* mapDesc,
  IImageDisplay* MapImage,
  BSTR searchString,
  VARIANT_BOOL Contains,
  BSTR searchFields,
  esriFindOption option,
  ILongArray* layerIds,
  IMapServerFindResults** findResults
);
[C++]

Parameters

mapDesc [in]

  mapDesc is a parameter of type IMapDescription

MapImage [in]

  MapImage is a parameter of type IImageDisplay

searchString [in]   searchString is a parameter of type BSTR Contains [in]   Contains is a parameter of type VARIANT_BOOL searchFields [in]   searchFields is a parameter of type BSTR option [in]

  option is a parameter of type esriFindOption

layerIds [in]

  layerIds is a parameter of type ILongArray

findResults [out, retval]

  findResults is a parameter of type IMapServerFindResults

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Remarks

Find performs a search based on a string value. This search can be conducted on a single field of a single layer, on many fields of a single layer or on many fields on many layers. Find returns a collection of objects that implement IMapServerFindResult.

Find requires a number of input parameters.  These include: a MapDescription, an ImageDisplay, the search string, a Boolean value on whether the search string is an exact match (False) or not (True), a comma delimited list of string values for the names of the fields you want to search, the esriFindOption, and an array of layer Ids to be searched.

Please note that Find only works with layer and does not work with StandaloneTable. It also does not honor any time setting of a layer.

MapDescription

The MapDescription contains all the LayerDescriptions in the map. These LayerDescriptions include a DefinitionExpression property. A DefinitionExpression can be set on a layer in order to limit layer features available for display or query. This expression can be set in the source map document as a definition query, or can be set using the DefinitionExpression property. The DefinitionExpression set in the LayerDescription will override any any definition query set in the source map. MapServer Find results should honor any definition query or DefinitionExpression set on the layer.

ImageDisplay

This is needed to determine whether layers are visible or not based on the current map scale.

Search Fields

If the searchFields parameter is blank all fields will be searched.

esriFindOption

The esriFindOption parameter includes: esriFindAllLayers and esriFindVisibleLayers.  If esriFindAllLayers is being used all layers are valid. If esriFindVisibleLayers is used, the search will be conducted only on layers that are visible in the map display. Layer visibility depends on whether the layer is on or off (the Visible property on ILayerDescription3) or whether the layer is on, but not visible due to scale dependencies (the MinScale and MaxScale properties on IMapLayerInfo2). The mapImage parameter is needed to determine whether the layer is not visible based on scale dependencies. This parameter can be Nothing/Null if esriFindAllLayers is used.

The parameters esriFindOption and LayerIDs behave like a boolean AND. There is no precedence. For example: if esriFindOption is esriFindVisibleLayers and pLayerIDs is Nothing/Null or empty, all the visible layers are searched. If esriFindOption is esriFindVisibleLayers and pLayerIDs contains only the first layer, the first layer is searched only if it is visible.

Results

Find always honors field visibility, and by default it respects field aliases and field formatting set in the source map document. If you want to use field names instead of field aliases, set ReturnFieldNamesInResults to True. When you want to have value in original data type (i.e. as Double instead of formatted string) so that you can do some computation (e.g. change the numeric or date to your locale settings), set FormatValuesInResults to False. It is important to note that these properties are only honored when the layer being searched implements IFeatureLayer (e.g. FeatureLayer). If the feature being queried has more than one field with the same alias (e.g. when joined), only one will be passed back to the client and the rest will be dropped from the result.

Geometry is always returned in the same spatial reference system as the DefaultMapDescription, even though the source data of a layer may be in a different coordinate system. The value of the Shape field in the result is a string showing the type of the geometry. To get the geometry associated with the result, use the IMapServerFindResult::FeatureShape property.

In some cases, for performance reasons, you may want limit or adjust the geometry being returned in the find result. Use ILayerResultOptions to manage this. If IncludeGeometry is set to False, FeatureShape returns nothing. This should increase performance in cases where feature geometry is large. When ILayerResultOptions is not used, FeatureShape returns geometry. If the Shape field is invisible in the source map, FeatureShape may still contain geometry depending on how IncludeGeometry is set by the user. You can also choose to densify or generalize the geometry returned in FeatureShape using GeometryResultOptions. Densification is used to better support clients that do not support Arcs (e.g. Bezier, Circular etc.). Generalization reduces the amount of geography being sent across the network and should lead to better performance. If LayerResultOptions are not specified for the LayerDescription, query results will include the original geometry.

Miscellaneous

There are two key differences between Find and the other query methods such as QueryData, QueryRowIDsQueryFeatureData etc. The first is that Find can work on multiple layers while the query methods work with a single layer. The second is that Find only works with a search string. The query methods use a queryFilter as a parameter. This allows the query to be based on either an attribute filter (SQL expression) or a spatial filter.

In order to control the amount of information MapServer needs to process for a query, a maximum number of records can be set. This value is contained in the MaxRecordCount property on IMapServerInit2. The default value for this property is 1,000. If 1,100 features match a given query only the first 1,000 results will be returned. You will be unable to access the remaining 100 records. To be able to access these records the MaxRecordCount would need to be increased to 1,100. MaxRecordCount can also be changed by modifying the MaxRecordCount XML tag in the MapServer's configuration file.

See Also

IMapServer2 Interface