Iris Classon
Iris Classon - In Love with Code

More on Search in WInRT: Search history

More on Search in WInRT: Search history
A few weeks back I asked on Twitter if you preferred to have search history on or off when doing searches in an application. The majority said off, some said a limited history and some preferred to have a button allowing them to toggle history on or off.

More on Search in Windows Store Apps:

SearchBox MVVM implementation with event arguments

Dirty fix: Search in Windows 8.1 does not work

Implementing Search in Windows Store Apps 8.1 – screenshot guide

Advanced searching with Windows 8 Search

User friendly SearchBox in Windows Store Apps: separators, suggestions and result items

How do we work with search history in Windows Store Apps?

SearchHistory is enabled by default but can be disabled with the SearchHistoryEnabled property, and you can even grab a SearchHistoryContext if you want different contexes depending on where the user does the search.

To access the global object that manages search, be that panel or SearchBox control, you can use the SearchSuggestionManager, found under: Windows.ApplicationModel.Search.Core.SearchSuggestionManager

clip_image001

Two methods might be of interest, ClearHistory and AddToHistory. The two do exatcly what you would think. It might be just me being tired, but I couldn’t figure out a better way to limit the search history items shown besides creating a limited queue adding search items to them as the user did the search, and clearing the list before appending the queue items.

It’s 5:20 AM so it might not be the best or brightest idea I’ve had, let me know if there are other ways. Anyway, there is a manager object, and methods to clear or add to the search history. Use them wisely.

Oh, and let’s not forget SetLocalContentSuggestionSettings, which:

Specifies whether suggestions based on local files are added automatically to the Suggestions collection, and defines the criteria that Windows uses to locate and filter these suggestions.

Basically you can provide suggestions based on local files, and you can pass in an Advanced Query Filter to grab exactly what you want, the folder used, properties to match etc. Quite neat.

  

[sourcecode language=“csharp”]

// searchbox or pane => they use the same manager

var searchManager = new Windows.ApplicationModel.Search.Core.SearchSuggestionManager();

// clear history

searchManager.ClearHistory();

// add to history

searchManager.AddToHistory(“Cute kittens”);

// Adding from limited queue

foreach (var historyItem in _searchHistory)

{

searchManager.AddToHistory(historyItem);

}

[/sourcecode]

Comments

Leave a comment below, or by email.


Last modified on 2014-03-25

comments powered by Disqus