Search w/ Dynamic Options via collection+json

By: Johnathon Wright on: February 11, 2014

We're searching for people using 'location', 'radius', and 'specialization' fields. Since collection+JSON apparently doesn't provide a mechanism for delivering options like the HTML tag <option>, we've forked the Ruby gem for collection+JSON and added that feature:

Find our repo with details at GitHub

Given I am an anonymous user
When I go to the search page
and I enter my postal code
And I select a specialty
And I submit the form
Then I should be on the results page
And I should see my criteria in an updatable form
And I should see the results

And another important scenario:

Given I am on the result page
Then I should see my search criteria
And I should see a list of the cities where the resulting people are located
And I should be able to filter by those cities.

Because of the second scenario, we need to pass back not just the results, but also the inquiry details, which will include our criteria and city list. Collection+JSON is implicitly limited to one kind of result per response, ie you can't have a collection with both an inquiry item AND a result item, since there is no rel-tag in the item. And even if there were a rel-tag... having two kinds of data mixed up together would be a giant mess.

So our challenge is to present meta-data about the search, available filters, and the results.

Our modified collection+json includes a 'related' collection which could hold the inquiry information. However, we need the expressiveness of the 'template' section for this task. So the 'items' collection links to the inquiry that has been submitted. items[0].links gives you a link to the results.

Our modified collection+JSON schema includes 'options' in the template/query section. This is the perfect mechanism for sending back the list of cities.

But that still leaves the problem of meta-data.... how many results were there? What page are we on? etc.

{
    "collection": {
        "href": "/inquiries/4.json",
        "items": [
            {
                "href": "/inquiries/4.json",
                "data": [
                    {
                        "name": "location",
                        "value": "70508"
                    },
                    {
                        "name": "radius"
                    },
                    {
                        "name": "specialization_id",
                        "value": "12"
                    }
                ],
                "links": [
                    {
                        "href": "/inquiries/4/results.json",
                        "rel": "specialist_search_results_resource"
                    }
                ]
            }
        ],
        "template": {
            "data": [
                {
                    "name": "inquiry[location]",
                    "prompt": "Location",
                    "value": "70508"
                },
                {
                    "name": "inquiry[search_area]",
                    "prompt": "Where are you looking?",
                    "options": [
                        {
                            "value": "local",
                            "prompt": "Close to Me"
                        },
                        {
                            "value": "us",
                            "prompt": "Anywhere in the US"
                        },
                        {
                            "value": "global",
                            "prompt": "Anywhere in the world."
                        }
                    ]
                },
                {
                    "name": "inquiry[specialization_id]",
                    "prompt": "Category",
                    "value": 12,
                    "options": [
                        {
                            "value": 1,
                            "prompt": "Rails"
                        },
                        {
                            "value": 2,
                            "prompt": "Ruby"
                        },
                        {
                            "value": 3,
                            "prompt": "AngularJS"
                        },
                        {
                            "value": 4,
                            "prompt": "jQuery"
                        }
                    ]
                }
            ]
        }
    }
}

In order to do this, we will need to have two kinds of locations... a home location and a cities collection. Our cities are actually CBSAs, so I'll call them Areas.

Since no values selected would necessarily mean no results, we'll assume a null value means all values. That way, the initial submit will come back something like this:

            {
                "name": "inquiry[home]",
                "prompt": "I live in",
                "value": "70508",
            },
            {
                "name": "inquiry[areas]",
                "prompt": "Locations",
                "value": [ 10100, 31080, 31060, 35440 ],
                "options": [
                    {
                        "value": 10100,
                        "prompt": "Aberdeen, SD"
                    },
                    {
                        "value": 31080,
                        "prompt": "Los Angeles"
                    },
                    {
                        "value": 31060,
                        "prompt": "Los Alamos, NM"
                    },
                    {
                        "value": 35440,
                        "prompt": "Newport, OR"
                    }
                ]
            }

Update

We've added a 'meta' element after some discussion





Comments:

vans said: Thank you a lot for providing individuals with a very breathtaking opportunity to discover important secrets from here. It is usually very great and stuffed with a lot of fun for me personally and my office peers to search your web site the equivalent of 3 times in 7 days to see the newest items you have. And indeed, I am just certainly astounded concerning the effective tips you serve. Selected 3 facts in this article are without a doubt the most impressive we've ever had. vans [url=http://www.vansshoes.us.com]vans[/url]

yeezy boost 350 v2 said: I together with my guys came going through the excellent guidelines from the website and suddenly came up with a horrible feeling I never expressed respect to you for them. All of the people were definitely for this reason passionate to read them and have now surely been taking advantage of these things. Thanks for indeed being well helpful and also for deciding upon certain superior issues most people are really eager to learn about. Our own sincere apologies for not saying thanks to earlier. yeezy boost 350 v2

nike air max said: I and also my pals came digesting the great secrets and techniques found on the blog while all of the sudden came up with a horrible feeling I never thanked the web blog owner for those strategies. My people ended up for that reason glad to read through them and have in effect honestly been using those things. Thanks for simply being so considerate and then for utilizing such very good ideas millions of individuals are really wanting to understand about. Our honest apologies for not expressing gratitude to earlier. nike air max

nike x off white said: I simply needed to thank you so much once more. I do not know what I might have worked on without these tips shown by you concerning this area. Certainly was a very difficult condition in my opinion, however , noticing your well-written avenue you treated that took me to cry over delight. Extremely thankful for this information and wish you realize what a great job your are providing educating many others by way of a site. I am sure you've never got to know all of us. nike x off white

a bathing ape said: I not to mention my friends have already been looking at the best thoughts located on your site and so quickly I got an awful feeling I never thanked you for those techniques. These people became absolutely passionate to read them and have honestly been making the most of these things. Thank you for genuinely indeed kind and then for settling on certain really good ideas millions of individuals are really desperate to know about. My personal honest apologies for not expressing appreciation to you sooner. a bathing ape

hermes belts said: I as well as my guys were found to be reading the excellent guides located on the website and all of a sudden came up with an awful suspicion I never expressed respect to the blog owner for those techniques. The guys came for this reason joyful to study all of them and have now actually been tapping into them. Thanks for simply being quite thoughtful and for picking such exceptional resources most people are really eager to learn about. Our own honest regret for not expressing gratitude to sooner. hermes belts

moncler jackets said: I precisely had to thank you so much again. I'm not certain the things I might have used in the absence of these ways discussed by you on such a problem. Entirely was a real alarming case in my circumstances, however , finding out your skilled form you processed that took me to leap over contentment. Now i'm happier for the help and sincerely hope you really know what a powerful job you are always putting in educating others using your blog post. Probably you've never got to know all of us. moncler jackets

yeezy boost 350 said: I truly wanted to post a note to be able to thank you for those splendid pointers you are placing at this website. My considerable internet lookup has finally been compensated with sensible knowledge to talk about with my close friends. I 'd tell you that we site visitors are truly endowed to live in a useful website with very many marvellous individuals with insightful opinions. I feel rather happy to have encountered your webpage and look forward to really more amazing times reading here. Thanks once more for all the details. yeezy boost 350

nike shox for women said: I needed to compose you a very little remark in order to say thanks a lot yet again on the beautiful suggestions you have shown in this article. This has been quite surprisingly open-handed of people like you to make freely exactly what a few people would have offered for an e-book to help make some bucks on their own, notably given that you might have done it if you considered necessary. These basics additionally worked to become fantastic way to be certain that other people have the same dreams the same as mine to see much more with respect to this problem. I'm certain there are lots of more pleasant periods up front for people who read your blog. nike shox for women
Back