BoboBrowser & Lucene.NET: Bool facet

347 Views Asked by At

I am using BoboBrowse together with Lucene.Net. There are some predefined facethandlers for different scenarios. My question: Does anyone know how to implement a handler for a bool type/property of a lucene document? I mean, from a facets search point of view theres just a field/facet with 2 different values "true" and "false", so the result contains that values of course. But the result set seems then a bit strange: 300 objects with true, 400 with false. With a bool value of false, the result set should contain all objects, with set to true only that 300.

Thanks.

1

There are 1 best solutions below

0
NightOwl888 On

With Bobo-Browse.Net, there are 2 different aspects of setting up a facet.

  1. Facets are defined at application startup and generally map to a specific field (or sometimes more than one field).
  2. Selections are defined at runtime and determine which values are included in the search. Generally speaking, selections act like boolean switches over each unique value in a field.

So, in the case of a "boolean" field (which is actually just plain text), you just have 2 possible values. But keep in mind, there are actually 3 selection states for this "boolean" field:

  1. Selecting "true"
  2. Selecting "false"
  3. Not selecting anything

It sounds like you just want to have your runtime code add/remove a single selection for "true", which will make it include all "true" values, or (if the selection is removed) include all values.

BrowseSelection sel = new BrowseSelection("booleanField");
if (value == true)
{
    // Add the selection to filter the result
    sel.AddValue("true");
}
else
{
    // Don't add a selection, and the result will not be filtered.
}
browseRequest.AddSelection(sel);

Have a look at my Faceted Search Prototype for an example how this can be set up on the UI (although this wasn't really meant to be a demo and has lots of commented garbage code in it, it does demonstrate the concept). If you want to omit the search part of it, you just need to use a MatchAllDocsQuery instead of parsing the query using QueryParser.