# How can I implement my own documentation search function?

The current documentation search doesn't allow for very sophisticate searching, can I write my own function to search through the docs?

### Update

This code is no longer the most up-to-date. The properly up-to-date code is in the package on GitHub.

For a run-down of the changes between this and that see the discussion between b3m2a1 and Nasser that starts here and the commit messages.

The key here will be that all properly written documentation pages have a "Metadata" TaggingRule.

Then we can use the PacletManager to search and scrape all of this. First we'll build an index of all this stuff and put it in $helpSearcherDocData loadDocumentationData[] :=$helpSearcherDocData =
Append[#,
"Pages" ->
Apply[Join]@
Map[FileNames["*.nb", Last[#], \[Infinity]] &, #["Directories"]]
] &@
<|
"Directories" ->
Join[
DeleteDuplicatesBy[#[[1]]["Name"] &]@
Select[DirectoryQ@*Last]@
Map[
# -> FileNameJoin[{#["Location"], "Documentation"}] &,
PacletFind["*"]
],
{"System" -> FileNameJoin[{$InstallationDirectory, "Documentation"}]} |> loadDocumentationMetadata[] := ( If[! AssociationQ@$helpSearcherDocData, loadDocumentationData[]];
$helpSearcherDocData["Metadata"] = Association@ Map[ # :> Set[$helpSearcherDocData["Metadata", #],
Append[
Fold[Association@Lookup[#, #2, {}] &,
"File" -> #
]
] &,
$helpSearcherDocData["Pages"] ] ) ensureLoadedDocumentationMetadata[] := If[! AssociationQ@$helpSearcherDocData || !
KeyMemberQ[$helpSearcherDocData, "Metadata"], loadDocumentationMetadata[] ] preLoadDocumentationMetadata[] := (ensureLoadedDocumentationMetadata[]; Scan[Identity,$helpSearcherDocData["Metadata"]])



For convenience we can then cache all this, so it's quicker to load later:

loadCachedDocumentationData[] :=
$helpSearcherDocData = Get[LocalObject["docsDataCache"]]; cacheDocumentationData[] := Put[$helpSearcherDocData, LocalObject["docsDataCache"]];


Then we can do simple searches on this "Metadata" dataset:

$helpSearcherDocMetadataDS :=$helpSearcherDocMetadataDS =
(
Dataset@
Select[Values@$helpSearcherDocData["Metadata"], KeyMemberQ["uri"]] );$helpSearcherDocMetadataDS[
Select[Length[#history] > 1 &&
0 < ToExpression@#history[[1]] < 8 &],
"context"
] // DeleteDuplicates // Normal

{"JLink", "NETLink", "WebServices", "ClusterIntegration", "", \
"GUIKit"}


This gives us the contexts that were documented before version 8.

We can then do searches on any of the following properties:

$helpSearcherDocMetadataDS[All, Keys] // Flatten // DeleteDuplicates // Normal {"built", "history", "context", "keywords", "specialkeywords", \ "tutorialcollectionlinks", "index", "label", "language", "paclet", \ "status", "summary", "synonyms", "tabletags", "title", \ "titlemodifier", "windowtitle", "type", "uri", "File"}  For instance let's get all of the obsolete functions: $helpSearcherDocMetadataDS[All, "status"] // Flatten //
DeleteDuplicates // Normal

{"None", "ObsoleteFlag"}

$helpSearcherDocMetadataDS[ Select[#type === "Symbol" && #status === "ObsoleteFlag" &], StringRiffle[URLParse[#["uri"], "Path"][[{1, -1}]], ""] & ] // Normal {"GUIKitBindEvent", "GUIKitCloseGUIObject", \ "GUIKitExposeWidgetReferences", "GUIKitGUIInformation", \ "GUIKitGUILoad", "GUIKitGUIObject", "GUIKitGUIObjectQ", \ "GUIKitGUIResolve", "GUIKitGUIRunModal", "GUIKitGUIRun", \ "GUIKitGUIScreenShot", "GUIKitIncludedScriptContexts", \ "GUIKitInitialArguments", "GUIKitInvokeMethod", \ "GUIKitInvokeThread", "GUIKitInvokeWait", "GUIKitName", \ "GUIKitPropertyValue", "GUIKitReleaseGUIObject", \ "GUIKitReleaseMethod", "GUIKitReturnScript", "GUIKitScript", \ "GUIKitScriptSource", "GUIKitSetPropertyValue", \ "GUIKitSetWidgetReference", "GUIKitSymbolicGUIKitXMLToWidget", \ "GUIKitTabs", "GUIKitUnsetWidgetReference", "GUIKitWidgetAlign", \ "GUIKitWidgetFill", "GUIKitWidgetGroup", "GUIKitWidgetLayout", \ "GUIKitWidget", "GUIKitWidgetReference", "GUIKitWidgetSpace", \ "GUIKitWidgetToSymbolicGUIKitXML", "GUIKit$GUIPath"}


From this data an update to the old help browser could even be rebuilt

Finally, here's a proper doc searcher that returns links to the proper doc pages:

helpSearch[selectionFunction_] :=


helpSearch[#type === "Symbol" && #status === "ObsoleteFlag" &]
`