locked
Search Charm for Split App with Multiple Posts Across Multiple Groups

    Question

  • I have seen several tutorials in the dev community docs on setting up the search contract to display search results from your app when you have one group (e.g. one blog feed). In my app I have multiple groups (i.e. multiple blog feeds using split app). I can get the searchResults.html page to display posts from across the different blogs, but the problem is when you click one - it doesn't take you to the right group showing the correct post. I assume I have to modify the "_itemInvoked" function in the searchResults.js file from what's below but can't figure it out. I am used to web databases where each displayed result would have a unique key (post ID) and blog group that I could pull to say use this blog group and get this post ID in the split.html template.

    _itemInvoked: function (args) {
    args.detail.itemPromise.done(function itemInvoked(item) {
    var index = Data.items.indexOf(item.data, 0);
    nav.navigate("pages/split/split.html", {group: item.data.group, selectedIndex: index });
    });
    },
    Would be great to see an RSSreader example that uses multiple feeds and a working search and share charm integration.

    Sunday, January 27, 2013 7:00 PM

Answers

  • I was able to come up with a workaround so that when an item is clicked from the searchResults.html page it knows which group (i.e. blog) the item (i.e. post) is associated to. The problem with the index is that it is using the order from the search results and not the order the post appears in from a particular blog feed. So my workaround was when I push the blog content (title, author, etc.) I also include the post index for the blog group. So now when the blog post appears in the searchResults.html page I have access to the correct index of the post for its own blog group, NOT the index of the search results.

    Original code found in various Dev Tutorials for searchResults.js

    _itemInvoked: function (args) {
                args.detail.itemPromise.done(function itemInvoked(item) {
                    // TODO: Navigate to the item that was invoked.
                    var index = Data.items.indexOf(item.data, 0);
                    nav.navigate("pages/split/split.html", {group: item.data.group, selectedIndex: index });

    My code after I added a postID to the blog array (in data.js)

    _itemInvoked: function (args) {
                args.detail.itemPromise.done(function itemInvoked(item) {
                    // TODO: Navigate to the item that was invoked.
                    nav.navigate("pages/split/split.html", {groupKey: item.data.group.key, selectedIndex: item.data.postID });
    Not sure if there is a better way or problem with my method, but it works from the initial tests I've done.
    • Marked as answer by hoWIWeb Tuesday, January 29, 2013 5:14 AM
    Tuesday, January 29, 2013 5:13 AM