build 2016 - p407 - advanced file searching in uwp

17
#Build2016 Searching your App’s Data in UWP Adam Wilson Program Manager

Upload: windows-developer

Post on 11-Apr-2017

242 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Build 2016 - P407 - Advanced File Searching in UWP

#Build2016

Searching your App’s Data in UWPAdam WilsonProgram Manager

Page 2: Build 2016 - P407 - Advanced File Searching in UWP

OutlineWhy search app data? Ways to search app data Indexed folder Content Indexer

Indexed folderUsing appcontent-ms filesIndexed folder sample

Content Indexer – the basicsPushing data in and checking the revision Searching and parsing the data coming outSample walkthrough

Page 3: Build 2016 - P407 - Advanced File Searching in UWP

• Users expect to find their data quickly• Some data can’t be shared with other apps • Common example is data synced from a cloud service• Apps can leverage the system search

functionality for their own data• Easy to use• Powerful query language using Advanced Query Syntax (AQS)• The same local search engine as Cortana, File Explorer, Outlook, and

more• Saves dealing with internationalization

Why Use System Search For App Data?

Page 4: Build 2016 - P407 - Advanced File Searching in UWP

• App writes data in a special, private, folder

• System manages making the data searchable

• Very simple to use, works with any data type

• Works best with static data

Indexed Folder

Page 5: Build 2016 - P407 - Advanced File Searching in UWP

• Push model • App gives the data to the system to make it searchable

• Very flexible in the type of data that can be pushed in

• Best used with transient data

Content Indexer

Page 6: Build 2016 - P407 - Advanced File Searching in UWP

Indexed Folder

Page 7: Build 2016 - P407 - Advanced File Searching in UWP

• Create a folder called indexed in the app data folder

• Put files in the folder

• That’s it

Using the Indexed Folder

StorageFolder indexedFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("indexed");

StorageFile newIndexedFile = await indexedFolder.CreateFileAsync("IndexedFile.txt");

Page 8: Build 2016 - P407 - Advanced File Searching in UWP

• Appcontent-ms files are metadata only files designed to work well with the indexed folder

• Follow the schema to create a file with the searchable data

• All the internationalization and AQS comes for free

Appcontent-ms files and the Indexed Folder

Page 9: Build 2016 - P407 - Advanced File Searching in UWP

Demo

Indexed Folder

Page 10: Build 2016 - P407 - Advanced File Searching in UWP

Content Indexer

Page 11: Build 2016 - P407 - Advanced File Searching in UWP

1. Open up a connection to the system index

2. Create the item to be pushed3. Push the item into the index4. Make sure the index was updated• Watch for revision number jumps

Using the Content Indexer

App AppApp App

1.

2.

3.

4.

Page 12: Build 2016 - P407 - Advanced File Searching in UWP

• Create a query and set the properties to be retrieved

• Parse the results back into your object model• Tip: Implementing IIndexableContent helps a lot

Pulling Data Out of the Content Indexer

App

?

App

?

App

?

1. Query for items

2. Receive query results

3. Parse back into object model

Page 13: Build 2016 - P407 - Advanced File Searching in UWP

Demo

Content Indexer

Page 14: Build 2016 - P407 - Advanced File Searching in UWP

Note on Reading the Property SystempropertyDescription   name = System.Music.AlbumArtist   shellPKey = PKEY_Music_AlbumArtist   formatID = 56A3372E-CE9C-11D2-9F0E-006097C686F6   propID = 13   searchInfo      inInvertedIndex = true      isColumn = true      isColumnSparse = true      columnIndexType = OnDisk      maxSize = 128      mnemonics = album artist

   typeInfo      type = String      groupingRange = Discrete      isInnate = false      canBePurged      multipleValues = false      isGroup = false      aggregationType = Default      isTreeProperty = false      isViewable = true      isQueryable = true      includeInFullTextQuery = false      conditionType = String      defaultOperation = Equal

propertyDescription   name = System.DateModified   shellPKey = PKEY_DateModified   formatID = B725F130-47EF-101A-A5F1-02608C9EEBAC   propID = 14   searchInfo      inInvertedIndex = true      isColumn = true      isColumnSparse = false      columnIndexType = OnDisk      maxSize = 128      mnemonics = modified|date modified

   typeInfo      type = DateTime      groupingRange = Discrete      isInnate = true      canBePurged      multipleValues = false      isGroup = false      aggregationType = DateRange      isTreeProperty = false      isViewable = true      isQueryable = true      includeInFullTextQuery = false      conditionType = String      defaultOperation = Equal

Property System Docs: http://aka.ms/windowsproperties System.AlbumArtist: http://aka.ms/albumartist System.DateModified: http://aka.ms/datemodifiedProperty System Docs: http://aka.ms/windowsproperties System.AlbumArtist: http://aka.ms/albumartist System.DateModified: http://aka.ms/datemodified

Page 15: Build 2016 - P407 - Advanced File Searching in UWP

Choosing Between the Content Indexer and Indexed Folder

Feature Content Indexer Indexed Folder

How data gets into the index App pushes the data, must listen to make sure indexing was successful

App creates files on the disk. Indexer manages the indexing process automatically

Type of data provided by app Property bags Any file type, metadata only appcontent-ms files can be used

Indexing Priority Control High priority and app controls indexing order

No control

Behaviour on reset App required to re-push data Indexer automatically reindexes all the files

Page 16: Build 2016 - P407 - Advanced File Searching in UWP

RecapTwo ways to search app data in the systemBoth provide the same powerful query functionality

Indexed Folder Easier to use

Content IndexerProvides greater flexibility for your schema

Page 17: Build 2016 - P407 - Advanced File Searching in UWP

© 2016 Microsoft Corporation. All rights reserved.