It is possible to keep drilling down to finer and finer granularity on date facets even when there is only 1 item left to display.
If there is only 1 item for the month of may 2012 it makes no sense that I can keep drilling down to day, hour, minute and second of the result.

Perhaps the module should stop adding more depth when the result count is at 1?

Comments

JvE’s picture

Status: Active » Needs review
StatusFileSize
new385 bytes

Attached patch works nicely on my site.

JvE’s picture

Title: Limit date facet hierarchy depth when there is just one result left. » Make date facet hierarchy depth configurable.
StatusFileSize
new385 bytes

Hm, never mind. With two or more items with the same date you still get the maximum drill-down without getting better results.

New patch introduces a new setting in the display options of the facet to adjust the finest "gap" the builder should go down to.

JvE’s picture

Doh, uploaded wrong file :(
Here's the correct one (I hope).

slucero’s picture

The previous patch worked well for me except for the case when there is only one search result. I've rerolled it with the adjustment to take care of that.

JvE’s picture

Status: Needs review » Reviewed & tested by the community
slucero’s picture

Found an additional check that needed to take place where the gap calculated and returned from facetapi needed to be checked and changed to the maximum granularity if it's more specific.

Rerolled the patch to include this check.

drunken monkey’s picture

Status: Reviewed & tested by the community » Needs work

Thanks for the great suggestion and your work!

In principle, I would agree with both additions, removing useless facet filters (although you should keep in mind to check whether the filter is AND or OR) and adding an option to restrict the depth. However, in its current form I've got several issues with your patch:

First off, it simply doesn't work for me. It seems that SearchApiFacetapiDate::build() is called before the adapter's buildRealm() method. Therefore, the query type cannot access the realm stored in the adapter, and therefore won't find the setting.

Also, both of the additions to the adapter class seem very hack-ish to me. Please ask Chris Pliakas in the Facet API issue queue on how to best add such settings.

And even if the $realm property stays, you should at least properly define and document it in the class, not just use it. Better still, define it as protected and also add a getter.
But, as said, only if Chris agrees this would be the best/only way to do this.

JvE’s picture

I guess the SearchApiFacetapiDate settings form items can be moved from the query type to the adapter with a check on $this->queryTypes[$facet['name']]. Then the adapter is no longer decoupled from the query types though. Any future query-types with settings shall entail changes to the adapter.

It may be possible to get the granularity setting in SearchApiFacetapiDate->build() with $facet->getSettings()->settings. Then the realm is no longer needed. It depends on the form you can build in SearchApiFacetapiAdapter->settingsForm().

Haven't encountered a case where build() was called before buildRealm() but I imaginge it could easily happen.

Since the patch from #3 is working fine for my customer's site I'm afraid I'm not going to be able to get any time to work on this.

gaëlg’s picture

#6 works for me but FACETAPI_DATE_YEAR => t('years'), is missing in the options array.

JvE’s picture

Status: Needs work » Needs review
StatusFileSize
new3.77 KB

By adding the "current search" module and block I also encountered the case where build() is called before buildrealm(), thus making it impossible to determine the realm in the query-type.

Attached patch has the settings "global" rather than per-realm which makes things a lot simpler.

I also adressed the "hackish" way the settings form was modified and let the adapter add the setting to the form rather than the query-type..

JvE’s picture

fixed Notice for facets that have no query type.

bago’s picture

#11 works fine for me!

bago’s picture

Status: Needs review » Reviewed & tested by the community
drunken monkey’s picture

Title: Make date facet hierarchy depth configurable. » Add option for maximum date facet depth
Status: Reviewed & tested by the community » Fixed

Works fine, thanks a lot for re-working the patch! I think it's acceptable here to just put the settings form inside the adapter. It would be cleaner to have it in the query type plugin, but this way it's acceptable, too.

So, committed. Thanks again!

Status: Fixed » Closed (fixed)

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