Support for date facets was added in #2611812: Create a date query type, but these need to use their own dedicated widgets.
This means that you can't show dates in a dropdown, or in checkboxes. There's a patch at #2862674: Provide an option on DateBasicWidget for displaying date with a dropdown widget to add support for dropdowns, as an option in the date widget.
I don't think this is the right approach, as this is going to multiply the number of options and duplicate code. It's also going to make it confusing for themers when things appear as dropdowns but are a different widget ID under the hood.
The problem is that widget options like raw results / links / checkboxes / dropdown should be independent of whether the values are dates or something else. In other words, turning timestamps into human-readable dates should be orthogonal to the choice of visual widget.
It seems to me therefore that the logical thing to do is move some of the date handling code to a processor.
Comment | File | Size | Author |
---|---|---|---|
#44 | move_date_handling_to_a-2896229-44.patch | 39.51 KB | StryKaizer |
#44 | interdiffie.txt | 708 bytes | StryKaizer |
Comments
Comment #2
borisson_I was running trough the list of issues earlier noticed that issue and was about to close (won't fix) because I figured that adding duplicates for all existing widgets would be too much work / maintenance. I agree that this approach is a more solid way to fix this. The only thing that I'm a little bit worried about is the
getQueryType
method is on the widgetInterface.We might have to move that to the facet-entity and make it configurable trough the UI.
If we do that - it's an API break and it would mean that this issue turns into a beta blocker.
Comment #3
joachim CreditAttribution: joachim at Torchbox commented> The only thing that I'm a little bit worried about is the getQueryType method is on the widgetInterface.
Yup, I spotted that, though I don't yet know what that's doing.
I'm having a stab at this, so assigning to myself.
Comment #4
borisson_Please remember that we still need to provide a way for widget to require / prefer specific query types. This is needed for range widgets, they should work for the range query type.
I think the
WidgetInterface::isPropertyRequired
can be used for that though.Comment #5
joachim CreditAttribution: joachim at Torchbox commentedRough outline of what I think needs to be done:
- move most of the code from DateBasicWidget to a new DateItemProcessor plugin (with changes to the form due to #2896237: processor plugins aren't using plugin configuration correctly...)
- add getQueryType() to the processor interface and base class. By default, this returns NULL.
- change WidgetPluginBase::getQueryType() to return NULL to mean 'use the default query type'
- change Facet::getQueryType() so it also calls the processors's implementations of getQueryType(). If the widget and all processors return NULL, the 'string' query type is used. If one or more return the same type, use that. If there is a disagreement between any of the processors and the widget, throw an exception (for now -- see #2895369: prevent unsuitable processors being added to facets).
- change query type plugins so instead of calling out to get configuration options (eg SearchApiDate::getGranularity(), getDisplayRelative(), etc), it's passed in to them by code that create the instance. This is necessary so that widgets and processors can have their query options merged. That could be done in DefaultFacetManager::alterQuery(), but it makes more sense for QueryTypePluginManager to override createInstance().
Comment #6
joachim CreditAttribution: joachim at Torchbox commentedUnassigning myself for the time being, as my project's going to need to see when there's budget to work on this.
Posting my work in progress patch in the meantime, in case anyone wants to work on it between now and when I come back to it.
Comment #7
borisson_#2896237 is fixed, so that shouldn't be a problem anymore.
Overall this sounds like a very solid approach to fix this problem.
This should also make the work going on in #2892620: As a sitebuilder I want a map to be exposed as a facet filter so I can narrow down results by dragging and zooming the map simpler. So I'm all for that!
Should we also tackle the same issues for the ranges here as well? We probably should do this all in one pass.
Comment #8
borisson_This is a start on all the required work. Needs test as well as .5 discussed in #7 to get this to actually work.
Comment #9
borisson_Back to needs work, sad that not a lot of our tests broke. Means that we really have to write more tests to make sure that this works as expected.
Comment #10
borisson_Comment #12
borisson_Comment #13
borisson_Also, should we write an upgrade path to change the widgets to links for everything that used datebasic?
Comment #14
mErilainen CreditAttribution: mErilainen at Wunder commentedI tested this and it works well. Leaving code review for someone more familiar with the module.
Comment #16
borisson_Doesn't work anymore now that we committed #2899947: Date list breaks when using exclude. Doesn't work yet with the patching I did to try and fix it.
Comment #18
borisson_Should be green now, with correct config object.
Comment #19
borisson_Comment #20
ekes CreditAttribution: ekes as a volunteer commentedJust throwing some things here as I work through the code. Core search hasn't been converted to 'type' base, but still field based. It certainly needs to always have a string.
Equally because it doesn't support range, yet it's easy to configure to do so without warnings and if a query type isn't supported an exception InvalidQueryTypeException is thrown from Facet::pickQueryType() it should probably be caught and watchdog/set message; as it stands the error isn't so helpful;
[edit] and I notice after conversation it's not what happens with mis-configurations where the widget doesn't match the processor: 'Invalid query type combination in widget / processors. Widget: %s, Processors: %s.'
Comment #21
ekes CreditAttribution: ekes as a volunteer commentedHard coding the exception for date_item into
QueryTypePluginManager::createInstance
and moving the configuration there makes the query both reliant on the processor, and makes it difficult for other processor combinations to pass on different configuration.Sticking with the granularity option which is clearly a query level option. Easy option the facet is available so in
getGranularity
ofSearchApiDate
: knowing its required processor it can just retrieve something like$this->facet->getProcessorConfigs()['date_item']['settings']['granularity']
. Equally a processor would be needed for other numbers (it's not yet updated yet?):SearchApiGranular
.Could something like granularity come from more than one processor? Probably. What then? Make explicit particular processor requirements?
Comment #22
ekes CreditAttribution: ekes as a volunteer commentedBeyond those two I think this does make it easier to reuse queries.
Also if I'm thinking this through correctly? For my forever plan to build native solr range facets (and probably better sql ones) it would be possible to create a (required) processor; a query using it; and then not have to recreate the widgets to show the output which would by that point be the same as the stuff produced by those horrid loops.
Comment #23
borisson_Comment #25
borisson_Comment #26
ekes CreditAttribution: ekes as a volunteer commentedJust reading through again:
Probably shouldn't be the 'Boolean processor' again.
Still don't like the selection method if() if() logic, still can' t think of a better way. Will try out basically extending it. If that's good then I think this should get in sooner rather than later :-)
Comment #27
borisson_Crediting ekes for the review work on this patch
Comment #28
borisson_Fixed the issue discovered in #26
Comment #29
StryKaizerTested and works as expected;
Very small nitpick in patch
Comment #30
StryKaizerNeeds upgrade path and reroll
Comment #31
StryKaizerReroll attached for tests.
I'll start working on upgrade path now
Comment #33
StryKaizerUpgrade path attached
Comment #34
StryKaizerRefactored the config keys to match more with what we are actually using them for ;)
Since we are doing an upgrade path, we can do this at once, as we need to migrate that specific config anyway.
Comment #35
borisson_Since we're renaming the config anyway, should we rename this to
date_granularity
? This doesn't just apply to this piece of the code but everywhere we're doing granularity things.Comment #36
StryKaizereh, I have not really an opinion about that. Both are fine for me. The other renames I did was because they were used wrong, thus making it not clear at all. This one makes sense already ;)
Comment #37
borisson_In that case, this looks solid!
Comment #38
borisson_Needs a reroll.
Comment #39
borisson_Reroll attached.
Comment #40
borisson_go testbot go.
Comment #42
StryKaizerReroll
Comment #44
StryKaizerClashing test name. C/P error
@borisson_ A beer will do ;)
Comment #46
borisson_Date handling is now better, fixed, thanks so much everyone!