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:

Just checking that you are human. What would be the result of this code?

a = 3*(4/2); b = 1; a+b

Thomas said: Accountant supermarket manager http://devinswany.com/stmap_31monane.html?lasuna.zaditor.fml.cialis priceline viagra 100mg CommScope intends to list its common stock on the Nasdaqunder the symbol "COMM". JPMorgan, Deutsche Bank Securities andBofA Merrill Lynch are the lead underwriters to the offering. (Reporting by Aman Shah in Bangalore; Editing by Maju Samuel)

Rafael said: Did you go to university? https://test.produkter.furnes.se/stmap_54yebbug.html?differin.adefovir.cialis phenazopyridine 200 mg The clause is inextricably linked to the birth of Pemex, a company that provides a third of the federal budget, and which has become firmly ingrained in the national psyche since its creation by President Lazaro Cardenas in 1938.

Kerry said: I support Manchester United https://baurzhan.kz/stmap_19zwkycw.html?accupril.levitra.valacyclovir.geriforte tylenol ibuprofen alternate toddler However, analysts say that while traffic is improving as a result of stepped-up discounts and the return of brands like St. John's Bay, there has been no evidence of a turnaround yet as the company heads into the bulk of the critical back-to-school shopping.

Arianna said: Sorry, I'm busy at the moment http://www.kobify.com/stmap_54yebbug.html?crestor.propafenone.levitra.zetia european paravolley championship Ibrahim Koroma, head of Sierra Leone's Criminal Investigations Department, said Leigh had breached the Public Order Act of 1965 by committing seditious libel. Leigh has not yet been officially charged.

Lenard said: Did you go to university? https://murariengineeringworks.com/pharmacy/stmap_19zwkycw.html?amiloride.viagra.sotalol.lotrel is amlodipine/olmesartan being recalled Diplomats from the five veto-wielding permanent members of the Security Council have been haggling over the details of a resolution to back an accord hammered out by Russia and the United States on September 14 in Geneva to eliminate Syrian President Bashar al-Assad's chemical weapons arsenal.

7 Inch TN TFT LCD Display WVGA 800*480 RGB 50 Pin said: Chemical Protection Suit 7 Inch TN TFT LCD Display WVGA 800*480 RGB 50 Pin

Madelyn said: Sorry, I'm busy at the moment https://www.bridgewaternj.gov/?s=Buy%20Cheap%20Viagra%20Online%20%E2%AD%90%20www.Pills2Sale.com%20%E2%AD%90%20Herbal%20Viagra%20Sainsburys%20-%20Viagra%20Ersatz viagra ersatz Once Awadallah established contact with the victims, and got their pictures or videos he, went back for more sources said. He allegedly threatened to tell their parents and friends if they didn't cooperate.

Mauro said: Do you know the address? http://ponce.inter.edu/?s=Buy%20Cheap%20Viagra%20Online%20%E2%AD%90%20www.Pills2Sale.com%20%E2%AD%90%20Viagra%20Beli%20Online%20-%20Efek%20Samping%20Minum%20Obat%20Kuat%20Viagra viagra beli online The deal will give EIG control of LLX. Batista, 56, currently LLX's largest shareholder, will leave LLX's board when the deal is finished but will retain a "relevant" stake and also have the right to name a member to the board.

Rosario said: I don't know what I want to do after university https://www.bridgewaternj.gov/?s=Buy%20Cheap%20Viagra%20Online%20%E2%AD%90%20www.Pills2Sale.com%20%E2%AD%90%20Merk%20Viagra%20Di%20Apotik%20-%20Viagra%20Red%20Tablet viagra red tablet Lebanese, Turkish and Syrian officials declined to immediately offer more details of the complicated, multilateral exchange. The deal appeared to be mostly mediated by the resource-rich Gulf state of Qatar, which has supported Syrian rebels in their battle against the Assad government. Palestinian officials also mediated.

Lanny said: I like watching football https://www.bridgewaternj.gov/?s=Buy%20Cheap%20Viagra%20Online%20%E2%AD%90%20www.Pills2Sale.com%20%E2%AD%90%20Can%20I%20Buy%20Viagra%20Over%20The%20Counter%20At%20Asda%20-%20Viagra%20Kaufen%20Ohne%20Rezept%20Per%20Nachnahme can i buy viagra over the counter at asda Based on the deliberations of a conference arranged by the U.S. Department of Agriculture, the report left experts as puzzled as ever. Environmentalists criticized that it emphasized mites but gave comparatively scant attention to pesticides' role.

Wilson said: An estate agents http://ponce.inter.edu/?s=Buy%20Cheap%20Viagra%20Online%20%E2%AD%90%20www.Pills2Sale.com%20%E2%AD%90%20Plant%20Viagra%206800mg%20-%20Viagra%20Sert%20A%20Quoi plant viagra 6800mg Harper and his aides were returning to Canada from Indonesiaon Wednesday and could not be contacted. Defence Minister RobNicholson, in overall charge of CSEC, says he cannot talk aboutnational security matters.

Savannah said: About a year https://www.bridgewaternj.gov/?s=Buy%20Cheap%20Viagra%20Online%20%E2%AD%90%20www.Pills2Sale.com%20%E2%AD%90%20Viagra%20Valor%20Na%20Drogasil%20-%20Viagra%20Super%20Dulox-force viagra valor na drogasil For all his notoriety in the board room, the bottom-line impact of Chevedden's work is hard to gauge. Big-money activists suggest the importance of small-scale operators like him is overstated. Chevedden's proposals generally seek procedural changes, and companies often aren't obliged to implement winning proposals.

Sheldon said: I can't get a signal https://www.bridgewaternj.gov/?s=Buy%20Cheap%20Viagra%20Online%20%E2%AD%90%20www.Pills2Sale.com%20%E2%AD%90%20Viagra%20Utan%20Receptfritt%20-%20Viagra%20Mastercard%20Buy viagra utan receptfritt BANGALORE, July 26 (Reuters) - Wipro, India'sthird-largest software services exporter, sounded upbeat aboutdemand for its outsourcing services, after posting an 11 percentrise in quarterly net profit helped by an increase in largecontracts.

Carlton said: Why did you come to ? https://abhikalpan.co.in/stmap_64kncqzz.html?cialis.trandate.celadrin.forzest vigora 100 ke side effects in hindi Around 2:30 p.m. ET, the buying started in the August $9strike calls and in the July $9 calls, trading started at 3:42p.m. ET for about 9 to 10 cents per contracts, according to datafrom Trade Alert, an options analytics firm.

Terrell said: I work for myself https://gruppogreggiurbani.com.ar/stmap_39dykkca.html?methotrexate.neoral.cialis artane dominos "Nashville" star Hayden Panettiere definitely hit a high note on the beach in Miami, where she spent her Easter weekend catching some rays with friends and making a splash in her bold, fuchsia bikini while frolicking in the sand. The 23-year-old actress has reason to smile. News recently broke of her engagement to pro boxer Wladimir Klitschko.

Jerald said: I'll call back later https://www.singingriverretirement.com/stmap_64kncqzz.html?symmetrel.amoxapine.viagra zelzah pharmacy He never would have agreed to participate in IVF had he known Schreiber might not have wanted him to be the father, he added."I was going to be the 'intended parent,' as that says [on the IVF forms, which Patric brought to the interview]," he said. "The word parent, if you look in the dictionary, means, 'to beget birth, nourish or raise a child.' And that was my intention."

William said: How would you like the money? http://www.rscdshamiltonandclydesdale.org.uk/stmap_39dykkca.html?snovitra.delgra.viagra sleepwell mattress internship Argentina's soyoil processing industry is now working at 75percent capacity "when idle capacity really shouldn't be morethan 10 or 15 percent," said Andres Alcaraz, spokesman for thecountry's CIARA-CEC grains export chamber.

sam said: great post. لعبة بادل

Back