Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Followup of #2600442: Add support for Facet Api in Drupal 8 - replaces #2602606: Create a date query type for facetapi (that was in the search-api queue)
We already created a String query type. We should also create one for dates.
Attached is a patch that's a WIP. This needs more work.
Comment | File | Size | Author |
---|---|---|---|
#45 | create_a_date_query_type-2611812-45.patch | 44.51 KB | borisson_ |
Comments
Comment #2
borisson_The patch here is very out of date, some of the functionality is already in http://cgit.drupalcode.org/facets/tree/src/Utility/FacetsDateHandler.php
Comment #3
joachim CreditAttribution: joachim as a volunteer commentedBlimey, so out of date that the namespace in the plugin file is still facetapi rather than facets!
Looking at rerolling this.
Comment #4
joachim CreditAttribution: joachim as a volunteer commentedHere's my work in progress.
It's working for me, but there are a few bits that aren't finished, because I don't understand the architecture involved:
- this currently needs LinksWidget::getQueryType() to be hacked so it returns the first item in $query_types rather than $query_types['string'], as for the date facet that isn't set! I don't understand what this is meant to be doing here -- can widgets only work with one query type?
- the earlier patch was getting config for the date granularity from the facet config. This is the same problem really: what would provide that UI? Are widgets per-query type?
- I've not refactored to use any code from FacetsDateHandler yet -- I figured I'd focus on getting it working first!
- I can't figure out why sometimes when I filter by a month I get the '(-)' next to the name of the month in the facet, and sometimes I don't!
Comment #5
zerolab CreditAttribution: zerolab at Torchbox for Mencap commentedComment #9
borisson_#4
Thanks for that patch!
Yes, for dates we would like to provide a seperate widget, see #2601302: Date widget: Date range - that is also a very old issue.
Since widgets are per query type, we can configure that trough the widget configuration.
That sounds like a solid approach, I agree.
I can't answer that yet, I haven't looked at the patch in detail yet. I think we'll get some time to work on this during drupal dev days in milan if no progress has been made before.
Thanks a lot for the work you did on this so far, and sorry for letting you wait for that long for this feedback.
Comment #10
joachim CreditAttribution: joachim as a volunteer commentedThanks for the review!
> Yes, for dates we would like to provide a seperate widget, see #2601302: Date widget: Date range - that is also a very old issue.
I can see that a date range widget would be useful, and specific to dates, but what I'm confused about is it you want a select list, or checkboxes that work similarly to the existing widgets.
Comment #11
ekes CreditAttribution: ekes as a volunteer commentedRefactored, with added basic widget, and work to general granularity/range (cf: #2627630: Provide a slider widget in Facets module and #2601302: Date widget: Date range)
There's an extended abstract class for executing queries with values in a range - this may or may not be useful for the slider case, it probably needs more data passed to the helper methods?
Implementation of this as a Granularity query class retrieves the value for the steps from the widget configuration. Should add a simple widget implementation for integers (1 - 10, 11 - 20...)
The date extension uses Y m d H i s logic instead of an integer for the granularity.
Comment #12
borisson_I like this, it looks like a good start, we'll need tests and additional documentation in all those new classes as well. I'll try to ping @Nick_vh for a review as well.
Comment #13
ekes CreditAttribution: ekes as a volunteer commentedOK checking a bit more work.
Adds relative date formatting (ago/hence):
Nick_vh mentioned this as desired functionality. I was rather hoping to inject DateFormatter and use that, but there was no control over start/end periods, so it's a full load of string concatenation to make the displayed text living in the query class. This because the Result object must be built there.
Adds some tests:
Note the reflection and mock is almost deliberately obtuse. The point being the query doesn't really need a widget, but that is where the bit of configuration it needs lives.
The SearchApiDateTest has to be based on KernelTestBase because DrupalDateTime also needs a live container which means it's actually there in that test.
There are no tests, yet, for the relative date formatting. This needs either copying the code into the test to work out the relative string for the REQUEST_TIME, or fixing the REQUEST_TIME. There's a patch for core that makes all this make sense #2717207: Add a time service to provide consistent interaction with time()/microtime() and superglobals probably worth testing for this case.
Adds a basic granular widget:
The default display text still needs to be changed. It should be $start - $end, at the moment it's just $start.
Comment #14
borisson_Setting to needs review to see how the bot feels about the added tests.
Comment #15
borisson_I had some time, so I fixed some coding standards things with this patch and also added a little bit of extra documentation. We still need to add more tests.
Comment #16
sylus CreditAttribution: sylus commentedI checked over the latest patch which works but I was still getting warnings:
I fixed up the warning by aligning the defaultConfiguration method to how other widgets are structured.
Comment #19
sylus CreditAttribution: sylus commentedSeems tests are broken but is unrelated to my slight fix.
Comment #20
edysmpThis patch fix the Exception
The created date does not match the input value.
when the Granularity is Year or Month.Comment #21
edysmpComment #22
kevinwalsh CreditAttribution: kevinwalsh commentedThis is working for me.
I just reported in https://www.drupal.org/node/2802571 that the facet block visibility settings do not allow you to set a "any value in X facet", so the user story of drilling down into date granularity, from Year to Month to Date, is not yet possible, which i believe worked pretty well in d7.
Comment #23
jespermb CreditAttribution: jespermb at Adapt commentedI have tested this issue and I can confirm that it works as expected.
There is a UX issue which I have reported here: https://www.drupal.org/node/2809223
Comment #24
borisson_Assigning to nick for review. This still needs an integration test. Not sure if we can test this without the widget that we'll provide for this. Need opinions if we can commit this already.
Comment #25
Nick_vhA boolean can never have the search_api_granular. I would rewrite this function to default to search_api_string and for specific types we should return the specific query types.
Is there any mathematical ordering defined? What will be computed first? Can this change over time with different PHP versions?
Comment #26
Nick_vhComment #27
acrollet CreditAttribution: acrollet commentedAttaching updated patch that applies to latest 8.x-1.x-dev - to be clear, this does not address Nick's feedback.
Comment #28
edysmp@acrollet Please add a interdiff.
Comment #29
borisson_Unassigned - feedback needs to be addressed and needs tests.
Comment #30
StryKaizerComment #31
StryKaizerComment #32
ruloweb CreditAttribution: ruloweb at Media.Monks commentedPatch #27 works ok for me :).
What if we want to use the date query type but display the facet using the Array widget? (for REST responses) as I can see now, there should be a new Widget for that, or maybe there should be an option in the Date Widget setting form to display it as a list of links or as a plain array.
Attached is patch which implements the first approach, also the interdiff between #20 and #27, there are just two line updated.
Thanks.
Comment #33
borisson_Let's see how the bots feel about this
Comment #38
borisson_I think the approach in #32 makes the most sense, the test fails are not related. This still needs an integration test.
Comment #39
webflo CreditAttribution: webflo at UEBERBIT GmbH commented$query_operator 'OR' should be lowercase.
Comment #40
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedComment #41
borisson_@webflo: does that also address #25?
Comment #42
webflo CreditAttribution: webflo at UEBERBIT GmbH commentedNo, only #39
Comment #43
borisson_In that case, back to NW based on #25.
Comment #44
borisson_Fixes #25, not sure if there's anything else we need to do.
Comment #45
borisson_@mollux has validated that this approach also works for ranges. I moved a file in the attached patch.
Comment #46
borisson_Thanks so much for the work on this patch! We decided to commit this and fix any other things that might need changing in followups.
Comment #48
borisson_