I have external sites in my Solr index, where the "bundle" field has no value, and I'd like to create a facet to include/exclude external sites in the search results. I basically want one option to filter all documents that have a value for "bundle", and another option to filter for those that don't.

I can replicate what I want by sending this to my Solr instance:

External docs:
select/?facet=true&q=my query&facet.field=bundle&fq=-bundle:[* TO *]

Internal docs:
select/?facet=true&q=my query&facet.field=bundle&fq=bundle:[* TO *]

I'm having a hard time figuring out what all I would have to implement in my module to get this working. Can anyone point me in the right direction?

CommentFileSizeAuthor
#8 facetapi_bundle_exists.tar_.gz1.48 KBkarlshea

Comments

cpliakas’s picture

So are you saying that the bundle field in the index may or may not have a value depending on whether it is an external site? If so, the "missing facet" might be what you are looking for.

karlshea’s picture

That's correct.

I saw the "missing facet" setting in the facet configuration, but I wasn't able to figure out what exactly that did.

Maybe I'm going about this the wrong way, but right now I'm implementing a query type in order to send the right information to Solr, and then will implement a facet on top of it to map the names I want to each choice.

I think the problem with using an existing facet query is that I don't want a list of all of the values of the bundle field, I just want exists/doesn't exist.

karlshea’s picture

I'm also having trouble figuring out how to make the active facet filter use radio buttons instead of checkboxes, there should only be a single active value allowed.

cpliakas’s picture

Not sure you need a new "query type" plugin. You are still doing a simple term query, correct? You should only be implementing this plugin if you are doing something like adding a wildcard query or geospacial query. If you alter the facet definition for the bundle and set the "facet missing allowed" key to true, it will automatically provide a facet that allows you to filter on items void of a bundle value.

In terms of the radios, you will need to implement a new display widget to do that. Effectively you will want to copy the FacetapiWidgetCheckboxLinks widget and add a jsSetting that is "makeRadios" or something like that. Include a JavaScript file similar to facetapi.js that makes a radio instead of a checkbox.

If you wanted to get creative, you could also patch the module and add a setting to the curent "Links with checkboxes" widget and provide an option to choose whether you are displaying radios or a checkbox. That would very much be welcomed.

karlshea’s picture

I need to aggregate all of the terms in the bundle field to "Internal" and then exclude all bundle fields as "external". It didn't seem like a term query could accomplish that, but I could be mistaken.

I'll put up the code after I get this cleaned up a little.

cpliakas’s picture

Ok, cool. Post back on your findings, because I am curious about what is needed to accomplish this use case.

Thanks,
Chris

karlshea’s picture

As I get into the radio buttons issue, it doesn't really seem like there's a good way to tell Facet API "I only want one possible value for this filter".

karlshea’s picture

StatusFileSize
new1.48 KB

Here is the mostly-working module that contains the facet and query type that I wrote, this way you can get the whole picture of what I'm trying to do.

I think I'm over my head trying to get a radio button display working. I have the radio buttons showing up, but I have no idea how to get Facet API to de-select all of the active filters for that facet and replace them with the clicked value.

karlshea’s picture

And actually, the more I think about it, radio buttons wouldn't work that well anyways. There wouldn't be any way to deselect a selected facet.

cpliakas’s picture

Hm, never thought of that! Maybe you would have to add an item that said "No filter"? Not exactly sure how you would add that off the top of my head.

cpliakas’s picture

Component: Code (functionality) » Code
Status: Active » Fixed

Marking support request as "fixed" since there is now some good documentation on how to create widgets.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.