The other option is to populate the ArcMap Document (mxd) tags with the layer names under File > Map Document Properties > Tags.
After populating afformentioned file(s) include folder with the mxd under the Search > Search options > Index > Register Folders and Server Connections
You can also automatically update the tag field by using the code taken from https://www.arcgis.com/home/item.html?id=18c19ec00acb4d568c27bc20a72bfdc8 and additionally modified (appends entries to the Tags field, and have the option not to open newly created MXD)
# Author: ESRI
# Modified: Damijan Bec
# Date: July 5 , 2010
# Modification Date: September 6, 2016
# Version: ArcGIS 10.0
# Modified Version: ArcGIS 10.4.1
# Purpose: This script will iterate through each layer in a map document and add
# the name of each layer as a tag value to the MXD. The tags are
# searchable via the search dialog and then MXDs can be identified
# based on the layers they contain. The script is intended to run
# from a script tool that requires four input parameters:
# 1) Browse to an existing MXD. (required)
# 2) Browse to and name an output MXD. (required)
# 3) Also include Group Layer names. (optional)
# 4) Open newly created MXD. (optional)
# The resulting MXD will (if the checkbox is checked) automatically open.
import arcpy, os
try:
# Read parameters from dialog
mxdPath = arcpy.GetParameterAsText(0)
outputMXD = arcpy.GetParameterAsText(1)
includeGroupLayer = arcpy.GetParameter(2)
openNewMXD = arcpy.GetParameter(3)
# Reference Map Document
mxd = arcpy.mapping.MapDocument(mxdPath)
# Generate unique, sorted list of layer names
layers = arcpy.mapping.ListLayers(mxd)
layerList = []
myWordList = []
for lyr in layers:
# Names of group/base layers, annotation classes are included
if includeGroupLayer == 1:
layerList.append(lyr.name)
else:
if not lyr.isGroupLayer:
layerList.append(lyr.name)
uniqueList = list(set(layerList))
wordTags = [x.strip() for x in mxd.tags.split(',')]
for word in wordTags:
myWordList.append(word)
# Update map document tags
filteredList = [item for item in uniqueList if item not in myWordList]
mergedList = filteredList + myWordList
mergedList.sort()
tagList = ",".join(mergedList)
mxd.tags = tagList
# save map document
mxd.saveACopy(outputMXD)
if openNewMXD == 1:
os.startfile(outputMXD)
del mxd
except Exception, e:
import traceback
map(arcpy.AddError, traceback.format_exc().split("\n"))
arcpy.AddError(str(e))
If you want to do a batch processing use the code below.
BEWARE:
Code won't allow you to create copy of the copy of MXD. E.g. It will allow you to create ArcMapDocument_tag.mxd but not ArcMapDocument_tag_tag.mxd.
There is an option to populate all existing (_tag.mxd included) MXDs though. The version below can also add Data Frame names to the Tag field. It continues if it cannot write into specific MXD file(s) because it is opened by another user (unecessary for the first script).
# Author: ESRI
# Modified: Damijan Bec
# Date: July 5 , 2010
# Modification Date: September 8, 2016
# Version: ArcGIS 10.0
# Modified Version: ArcGIS 10.4.1
# Purpose: This script will iterate through each layer in a map document and add
# the name of each layer as a tag value to the MXD. The tags are
# searchable via the search dialog and then MXDs can be identified
# based on the layers they contain. The script is intended to run
# from a script tool that requires three input parameters:
# 1) Path to the folder with MXD files. (required)
# 2) Option to include Data frames, Group layers, Annotation classes names. (optional)
# 3) Option to populate existing MXD files. (optional)
import arcpy, os
try:
# Read parameters from dialog
mxdPathFolder = arcpy.GetParameterAsText(0)
includeDataFrame = arcpy.GetParameter(1)
overwriteExistingMXD = arcpy.GetParameter(2)
for root, dirs, files in os.walk(mxdPathFolder):
for name in files:
fileName = os.path.join(root, name)
if ".mxd" in fileName:
# make sure that you do not end up with filename_tag_tag_tag_tag.mxd or so
if "_tag.mxd" in fileName and overwriteExistingMXD == 0:
arcpy.AddMessage(
"You already ran this tool. There is no need to run it again. Use overwrite if you want to update all existing MXD (including *_tag.mxd) and its tags")
else:
# Reference Map Document
mxd = arcpy.mapping.MapDocument(fileName)
layerList = []
myWordList = []
dataFrame = arcpy.mapping.ListDataFrames(mxd)
layers = arcpy.mapping.ListLayers(mxd)
# first loop only through data frames
for frame in dataFrame:
if includeDataFrame == 1:
layerList.append(frame.name)
# now loop also through layers and append layer names to the list
for lyr in layers:
if includeDataFrame == 1:
# Names of group/base layers, annotation classes are included
layerList.append(lyr.name)
else:
if not lyr.isGroupLayer:
layerList.append(lyr.name)
uniqueList = list(set(layerList))
wordTags = [x.strip() for x in mxd.tags.split(',')]
for word in wordTags:
myWordList.append(word)
# Update map document tags
filteredList = [item for item in uniqueList if item not in myWordList]
mergedList = filteredList + myWordList
mergedList.sort()
tagList = ",".join(mergedList)
mxd.tags = tagList
if overwriteExistingMXD == 1:
# save map document
try:
mxd.save()
except Exception, e:
import traceback
map(arcpy.AddError, traceback.format_exc().split("\n"))
arcpy.AddError(str(e))
# nice message for mere mortals that will not flee away
failed = "File cannot be saved as it is opened by someone else. If mxd is stored on network drive or in shared folder find who has opened it. This is the file in question: " + mxd.filePath + ". Lets continue."
arcpy.AddMessage(failed)
else:
fileName = fileName[:-4] + "_tag.mxd"
try:
mxd.saveACopy(fileName)
except Exception, e:
import traceback
map(arcpy.AddError, traceback.format_exc().split("\n"))
arcpy.AddError(str(e))
# nice message for mere mortals that will not flee away
failed = "File cannot be saved as it is opened by someone else. If mxd is stored on network drive or in shared folder find who has opened it. This is the file in question: " + mxd.filePath + ". Lets continue."
arcpy.AddMessage(failed)
del mxd
except Exception, e:
import traceback
map(arcpy.AddError, traceback.format_exc().split("\n"))
arcpy.AddError(str(e))