How to check if facet is selected

Hi there,

I am building an application here with some facets that I represent as
checkboxes. On each checkbox click I send such a parameter: ?
selected_facets=priceEUR_[100.0-200.0] and them my server-side
controller is building a request to ES.
The JSON that I get back is something like this:

"facets" : {
"description" : {
"Type" : "terms",
"missing" : 5437,
"terms" : [ ]
},
"name" : {
"Type" : "terms",
"missing" : 5437,
"terms" : [ ]
},
"priceEUR" : {
"Type" : "range",
"ranges" : [
{
"from" : 0.0,
"to" : 5.0,
"count" : 595,
"total" : 1457.8904200000002,
"mean" : 2.4502360000000003
},
{
"from" : 100.0,
"to" : 200.0,
"count" : 2207,
"total" : 879698.2974919997,
"mean" : 398.59460692886256
},
{
"from" : 5.0,
"to" : 100.0,
"count" : 2096,
"total" : 67012.99705100003,
"mean" : 31.97184973807253
}
]
}
}

and so I pass it to the JSP and iterate to display the checkboxes
again. My problem comes when I have to decide whether a checkbox is
checked or not. It would be really nice if priceEUR facet had a
'selected' attribute, or smth to distinguish the selected value, like
the one below:

"priceEUR" : {
	"Type" : "range",
	"ranges" : [
		{
			"from" : 0.0,
			"to" : 5.0,
			"count" : 595,
			"total" : 1457.8904200000002,
			"mean" : 2.4502360000000003
		},
		{
			"from" : 100.0,
			"to" : 200.0,
			"count" : 2207,
			"total" : 879698.2974919997,
			"mean" : 398.59460692886256,
                            "selected" :

true
<<<<-------------------------------------|||||
},
{
"from" : 5.0,
"to" : 100.0,
"count" : 2096,
"total" : 67012.99705100003,
"mean" : 31.97184973807253
}
]
}

I can, of course do some computation in the controller and alter the
returned JSON, but I thought it would be a nice feature for ES to
return the selected value.

Thank you for your time.

'Selected' can mean a lot of different things. What if you want to
'select' two values? (combination via OR)

I think you have to look into the original query to get information of
how and which values are filtered.

For jetwick I'm even more lazy and put my custom query object into the
session so that I can just do filterQueries.contains(xy) ...

Regards,
Peter.

On Apr 20, 10:00 am, paranoiabla paranoia...@gmail.com wrote:

Hi there,

I am building an application here with some facets that I represent as
checkboxes. On each checkbox click I send such a parameter: ?
selected_facets=priceEUR_[100.0-200.0] and them my server-side
controller is building a request to ES.
The JSON that I get back is something like this:

"facets" : {
"description" : {
"Type" : "terms",
"missing" : 5437,
"terms" :
},
"name" : {
"Type" : "terms",
"missing" : 5437,
"terms" :
},
"priceEUR" : {
"Type" : "range",
"ranges" : [
{
"from" : 0.0,
"to" : 5.0,
"count" : 595,
"total" : 1457.8904200000002,
"mean" : 2.4502360000000003
},
{
"from" : 100.0,
"to" : 200.0,
"count" : 2207,
"total" : 879698.2974919997,
"mean" : 398.59460692886256
},
{
"from" : 5.0,
"to" : 100.0,
"count" : 2096,
"total" : 67012.99705100003,
"mean" : 31.97184973807253
}
]
}

}

and so I pass it to the JSP and iterate to display the checkboxes
again. My problem comes when I have to decide whether a checkbox is
checked or not. It would be really nice if priceEUR facet had a
'selected' attribute, or smth to distinguish the selected value, like
the one below:

    "priceEUR" : {
            "Type" : "range",
            "ranges" : [
                    {
                            "from" : 0.0,
                            "to" : 5.0,
                            "count" : 595,
                            "total" : 1457.8904200000002,
                            "mean" : 2.4502360000000003
                    },
                    {
                            "from" : 100.0,
                            "to" : 200.0,
                            "count" : 2207,
                            "total" : 879698.2974919997,
                            "mean" : 398.59460692886256,
                            "selected" :

true
<<<<-------------------------------------|||||
},
{
"from" : 5.0,
"to" : 100.0,
"count" : 2096,
"total" : 67012.99705100003,
"mean" : 31.97184973807253
}
]
}

I can, of course do some computation in the controller and alter the
returned JSON, but I thought it would be a nice feature for ES to
return the selected value.

Thank you for your time.

Hi Karussell,

of course it doesn't make much sense if you use a mixture of AND/OR
filters,
but I still think it would be useful in the case when you use only OR
or AND queries.

I have the original values and I am currently setting the
selected:true in the JSON by
myself and it works great. I still feel it looks ugly though.

Cheers, Petar.

On Apr 20, 11:13 am, Karussell tableyourt...@googlemail.com wrote:

'Selected' can mean a lot of different things. What if you want to
'select' two values? (combination via OR)

I think you have to look into the original query to get information of
how and which values are filtered.

For jetwick I'm even more lazy and put my custom query object into the
session so that I can just do filterQueries.contains(xy) ...

Regards,
Peter.

On Apr 20, 10:00 am, paranoiabla paranoia...@gmail.com wrote:

Hi there,

I am building an application here with some facets that I represent as
checkboxes. On each checkbox click I send such a parameter: ?
selected_facets=priceEUR_[100.0-200.0] and them my server-side
controller is building a request to ES.
The JSON that I get back is something like this:

"facets" : {
"description" : {
"Type" : "terms",
"missing" : 5437,
"terms" :
},
"name" : {
"Type" : "terms",
"missing" : 5437,
"terms" :
},
"priceEUR" : {
"Type" : "range",
"ranges" : [
{
"from" : 0.0,
"to" : 5.0,
"count" : 595,
"total" : 1457.8904200000002,
"mean" : 2.4502360000000003
},
{
"from" : 100.0,
"to" : 200.0,
"count" : 2207,
"total" : 879698.2974919997,
"mean" : 398.59460692886256
},
{
"from" : 5.0,
"to" : 100.0,
"count" : 2096,
"total" : 67012.99705100003,
"mean" : 31.97184973807253
}
]
}

}

and so I pass it to the JSP and iterate to display the checkboxes
again. My problem comes when I have to decide whether a checkbox is
checked or not. It would be really nice if priceEUR facet had a
'selected' attribute, or smth to distinguish the selected value, like
the one below:

    "priceEUR" : {
            "Type" : "range",
            "ranges" : [
                    {
                            "from" : 0.0,
                            "to" : 5.0,
                            "count" : 595,
                            "total" : 1457.8904200000002,
                            "mean" : 2.4502360000000003
                    },
                    {
                            "from" : 100.0,
                            "to" : 200.0,
                            "count" : 2207,
                            "total" : 879698.2974919997,
                            "mean" : 398.59460692886256,
                            "selected" :

true
<<<<-------------------------------------|||||
},
{
"from" : 5.0,
"to" : 100.0,
"count" : 2096,
"total" : 67012.99705100003,
"mean" : 31.97184973807253
}
]
}

I can, of course do some computation in the controller and alter the
returned JSON, but I thought it would be a nice feature for ES to
return the selected value.

Thank you for your time.

Hi Petar!

of course it doesn't make much sense if you use a mixture of AND/OR
filters,
but I still think it would be useful in the case when you use only OR
or AND queries.

Yes this would be useful. But I don't think it relates into the core
of ES. (Also in solr there is no such feature)
Maybe it should be done in a separete facet helper plugin or
something.
Then various multiselect scenarios could be recognized - that would be
very neat - also for me :wink:

I have the original values and I am currently setting the
selected:true in the JSON by
myself and it works great. I still feel it looks ugly though.

Why do you need to set it to true?
Do you mean you have a controller and you want to make it easier for
the view?
This does not sound ugly IMHO.

Regards,
Peter.