How to index app local data
In Windows 8, you can index the local stored data for your app via the Windows Search Service (WSS).
If your app manages files such as documents, email, or media (such as photos, music, and video), there is a central requirement to index the contents or properties of the files structurally, so that users are able to manage and retrieve the data in a quick and efficient fashion. You do not need to build the indexer within your app. There is a convenient and secure option for you as the app developer: you can just enable Windows Search Service to index your app data.
The main advantages in using WSS to index your app data are:
- WSS supports indexing the full content text of most commonly used document types. In addition, WSS also supports indexing the file properties.
- With built-in Search contract and file APIs, indexed data can be easily fetched and reused.
- Windows Search respects the file system security settings, which maintain the indexed app data securely stored in the Windows indexer.
To request Windows Search to index the app data is effortless. You need to create a folder named “indexed” under the app data folder and store the contents that need to be indexed within. Windows Search treats the indexed folder just like any other indexing location on the hard drive. It will index the file contents or file metadata (properties) in this folder and all its subfolders. Here is a list of important considerations:
- The ‘indexed’ folder must follow these guidelines:
- The indexed folder must be created under the localFolder root. Windows search does index the contents in this folder deeply. Any file that is locally stored in this folder or its subfolders (including all levels of subfolders) will be indexed. Only one indexed folder per app is allowed.
- The folder name “indexed” is not case sensitive.
- Though the app data folder is called localFolder in the Windows Runtime API, it is named LocalState on the physical hard drive. If you want to access this folder for testing purposes, use this folder path: %user%\ AppData\Local\Packages\%packageName%\LocalState
- The folder structure under the “indexed” can be deep, but the Windows API doesn’t allow the length of the path for a file/folder longer than MAX_PATH, which is defined as 260 characters. Therefore developers need to ensure that the files and folders under the indexed folder do not exceed this limit. Please refer to this page for more info about MAX_PATH.
- Windows Search only indexes the local stored data, therefore, only the files that are locally stored in the indexed folder or its subfolders will be indexed.
- The indexed folder cannot be created during installation. It can only be created when the app is running. Since it takes time for Windows Search to complete, depending on the content size, we recommend that you create the indexed folder when the app is first run. Once the indexed folder is created, Windows Search will automatically index the app content. If the files or subfolders are modified (added, deleted or updated) , Windows Search will also automatically reschedule an indexing process and keep the indexer updated with the changes. Note that Windows Search monitors the CPU usage to optimize the indexing process on its own schedule.
Windows Search Service respects the security settings of Windows File system such that the indexed app data are stored in indexer securely. In particular:
- When multiple user accounts are on the same machine: Windows 8 apps are installed per user account. If there are multiple users on the same machine using the same app, each app instance would create its own indexed folder under different physical path. Therefore one user cannot access the indexed data under other accounts unless this user is granted the access to that physical path.
- When app data for multiple apps is indexed: Windows File system does not allow one app to access the data of another app directly. So an app does not have access to another app’s indexed data.
Once the app data is indexed, the app can fetch the data via the file API.
- Windows Search Service
- How Windows Search Service index the content via IFilters
- Adding search to Windows Store apps
Build date: 11/16/2013