Problem/Motivation
As a user narrowing the search results, using facets, I want to be able to see a summary of my active filters, so that I can have very quick a "big picture" of what is selected. See an example of such summary block in this picture.
Proposed resolution
Create a new block that shows a summary of filters based on the facets source. Make this block fully configurable and themable.
The solution can be implemented in three ways:
- Directly in Facets module.
- In a Facets submodule.
- As a contrib module
Probably the 3rd option is the most flexible but still needs some changes in Facets itself in order to work. I've implemented the solution 2. in the patch but I'm ready to switch to 3. if the module maintainers are OK with the changes to Facets.
Remaining tasks
- Choose the way to implement (see above).
- Implement the new
FacetSourcePluginInterface::getTotalCount()
for core search. In the patch this was not solved.
User interface changes
A new, fully configurable and themable block that shows the filters/facets summary.
API changes
New method getTotalCount()
in \Drupal\facets\FacetSource\FacetSourcePluginInterface
.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#73 | introducing_the_current-2735891-73.patch | 92.41 KB | borisson_ |
#8 | summary-2735891-6-only-facets.patch | 5.83 KB | claudiu.cristea |
Comments
Comment #2
claudiu.cristeaComment #3
claudiu.cristeaComment #4
borisson_What the difference between this and #2669556: Port Current Search Block functionality? I'll do a more in depth review tomorrow morning at the frontendunited sprint.
Comment #5
borisson_I like the code and the approach that you took to do this, I still don't see the difference between this and the current search block. I did see some things that I'd change. I'll ping StryKaizer to see if he has anything to say about this.
If you agree that this is essentially the same thing as the current search block, I'd love to take approach 2 and keep this in facets as a sub-module.
I did have some nitpicks.
I see you used the empty_message as a string here, I think it'd be a good idea to use the same approach for the facet entity. However, we use empty_behavior there, we should probably use the same for both entities.
Not sure which one we should use though. Any preference?
Can we move this up, so this is above the methods in the class?
I'd love it if we can put that return as early as possible so we can avoid the
else
here.This change will clash with a recent change in #2722783: Deleting a facet source leads to a fatal error on trying to edit facets associated with that facet source. Just letting you know.
Did we need this change?
Comment #6
claudiu.cristea@borisson_, I know nothing about Current Search module. The problem is that I don't have time to make an evaluation and, possibly, port that. I need this for a project I am working on. I would be very thankful if you and the other maintainers can make a decision. If you decide to go with the other approach then is no problem for me, I will make this a contrib. But there's still a part that needs your help. We need a way to get the total number of records from the source. At least I need you to commit the addition to the source plugin interface:
FacetSourcePluginInterface::getTotalCount()
together with the implementations in\Drupal\facets\Plugin\facets\facet_source\SearchApiBaseFacetSource
and core search (note that I didn't implement the core search ::getTotalCount() because I didn't have time to research how to do it). If you decide that this will no go in Facets a will provide patch with only those changes that applies to Facets.Let me know.
On #5...
#5.1: Right! Agree and changed to use more structured info. Also introduced the formatted text. But beware about the current implementation of empty_behavior in
\Drupal\facets\FacetManager\DefaultFacetManager::build()
. As is implemented now:Is not using the format that was store. Look at my patch how I implemented that. Probably this need a followup.
#5.2: OK.
#3.3: I understand but there the time/resources consumer is above, outside if:
$facet_source_plugin->getTotalCount()
. The if() and elseif() evaluations are very fast. It would be confusing to revert the evaluation just to get that on top. And anyway it would involve the same function calls so not really any gain. As is now is more "code readable".#5.5: Ouch, thank you!
Comment #7
borisson_I discussed this a little with StryKaizer already, we did see that this is the same as the current search module. Closed that issue in favor of this one.
Comment #8
claudiu.cristeaHere's patch only for facets part in the case we go with facets_source_summary as standalone contrib.
Comment #9
claudiu.cristeaOuch, missed a semi-colon in yml.
Comment #10
claudiu.cristeaOthers...
Comment #11
claudiu.cristeaSmall fixes.
Comment #12
claudiu.cristeaAdded cache context on query string. Also provided a link in the admin list in the source row as a new operation.
Comment #13
StryKaizerHi, thanks for starting to work on this. This is actually the "Current Search Blocks" functionality as was a submodule in facet_api d7. We had some discussion already concerning this so I'll list a few things about what we had in mind here.
We want all features which facet_api d7 offered to be ported, and make it pluggable for new features.
See #2669556: Port Current Search Block functionality and #1375674: How do I use the new Current Search Blocks module?
Some missing features in current patch are:
- Allow to show full_text search (currentsearch-item plugin, see below)
- Allow block display setting following these rules
-- Display only when keywords are entered.
-- Display on empty searches where no keywords are entered.
-- Display only when one or more facet items are active.
-- Display when either keywords are entered one or more facet items are active.
- Create a new plugintype which allows creation of new currentsearch-items and ship with at least 2 default ones, being "Custom Text" and "Active items", see facet_api d7
- Show currentsearch items in facet overview page grouped by facetsource, under or above the facets.
- I prefer renaming the submodule to "Current search blocks" (what d7 used) instead of "Facets Source Summary" to not confuse people. (EDIT: lets discuss this, summary on the other hand is a good name ;-) )
- Allow creation of multiple summary blocks per facet source, this is needed if people want different summaries depending on e.g. the display setting, so lets use a config entity for current_search, similar to a facet, instead of 1 default block.
- Allow deselection on facet-items in the current_search block, e.g. MyFacet (x)
I understand that moving to config entities instead of 1 default block per facet is a big change, but we really need to cover as much use-cases here.
Comment #14
claudiu.cristeaThank you. At this stage the patch is solving my need in a project. I will not have full time to complete all requirements. However, if there will be some team work I'm happy to contribute. I'm also available for code review.
Comment #15
StryKaizer@claudiu.cristea
No problem at all, thanks for starting on this! I'll start working on the current search functionality and will let you know when I need a code review ;-)
Comment #16
claudiu.cristeaI'm for
facets_summary
. The name in the patch is too long. But, right, 'summary' is more descriptiveComment #17
borisson_Back to NW based on #13. Starting on this now.
Comment #18
borisson_So, I tried to work on this yesterday / today. It looks like this isn't as easy as I thought and I don't really understand everything very well either. So attached patch is WIP but not planning to do more work on this today.
Comment #19
claudiu.cristea@borisson_, is it possible to add an interdiff for #18 so that I can review? Thank you
Comment #20
borisson_@claudiu.cristea, I started from scratch again, so no interdiff is available. I figure I probably won't do any work on this @ dev days anymore. The patch also doesn't do anything yet (nothing really works except saving the config entity).
Comment #21
Nick_vhRerolling
Comment #22
Nick_vhThere were some more basic failures in there. This now allows creation and deletion of those facet summary blocks. Will try to figure out now what else we need to copy from the work that was done earlier to make this work.
Comment #23
claudiu.cristeaWait, wait, wait! Why starting from 0 in #18 while there's a good starting patch in #12?
Comment #24
borisson_As discussed in milan, Nick will merge in all functionality from #12 into the last patch.
Comment #25
Nick_vhProgress. Able to store the config entities already. Next up is the derived block & checkup of the functionality. Review is already welcome but will need some more work to get it back to the functional state of #12
Comment #26
Nick_vhBlocks are being derived. I have to stop now but the work remaining is to create a build processor to add the counts. What also needs to happen is to make it pluggable so that we can add different types of current search items as mentioned by @strykaizer. Right no wit has the "old" facets logic in the patch but that is not being saved yet.
Comment #27
StryKaizerTried patch in #26which threw following error:
Fatal error: Call to a member function loadMultiple() on null in /path/to/facets/facets_summary/src/Plugin/Block/FacetsSummaryBlockDeriver.php on line 60
@Nick_vh: am I missing something?
Also small note, at this moment current_search is a submodule but is used in facetlistbuilder anyway, which throws an error when not enabled. We should fix that too in this patch.
Comment #28
claudiu.cristeaSorry. I don't know what to review. First we have to start from a working patch and that is #12. Secondly, I cannot review those patches because there's no interdiff, so it's hard to track. My proposal is to start from #12 and progressively add the functionalities described in #13 by @StryKaizer.
To do so, I'm proposing:
facets_source_summary
tofacets_summary
. Nothing else.In this way we can easily track the progress. Otherwise it seems chaotic for me.
Comment #29
StryKaizerComment #30
mpp CreditAttribution: mpp as a volunteer and at AmeXio commentedThere seems to be a typo in #26:
class property:
in create:
but in getDerivativeDefinitions:
The patch no longer applies.
Comment #31
claudiu.cristeaComment #32
Nick_vhNo more failures at least. Now we're ready to move on
Comment #33
claudiu.cristeaComment #34
Nick_vhThe blocks show up again but now the facets don't want to appear. Debugging slowly but feel free to take a look already at the general concepts here.
Comment #35
Nick_vhThe following patch is in a working state and has 3 processors on top of the actual current search facets:
What it doesn't do:
No support for ordering
I'm quite happy with how this turned out after DrupalCon Dublin. Please take a look and try it out. I'm sure there are still bugs in here and cleanup todo.
Also I tried to install it from scratch and use it, so hopefully this also works for someone else.
Comment #36
Nick_vhBefore I continue, I'd like some review and someone actually testing this.
Comment #51
Nick_vhSome of my thoughts of what still needs to happen:
We need the capability to style the results in the same way as regular facets. Since the facet results are an array of Results this is actually quite easy to do. Same for the sorting of them, and this way we could reuse email existing processors and potentially even the widgets in facets so that we do not have to duplicate effort. However, I would like the current functionality to go in first as experimental because it is in a working phase and architecturally I don't think it prevents any of this to happen. I started to duplicate the sort processors initially but it felt wrong.
Obviously the test failures need to be resolved as well :-)
Comment #52
Nick_vhAdded a count processor but the count coming back from the query doesn't seem to be accurate. Could be a Search API bug.
Comment #55
borisson_@Nick_vh #2809753: getFacets in search_api_db returns wrong resultset might be the bug you're seeing.
Comment #56
Nick_vhThis should fix the testbot. At least they pass locally... Let's see. Also, the count should be fixed, but I'm really surprised I needed a global variable for that. This is weird, but apparently that's how core does it.
Comment #57
Nick_vhWoot, passing. Can someone do the code review? There are no tests yet so I'd like to discuss a strategy of getting this in. Most of it is a separate module so what if we get that in and classify it as experimental? Perhaps a small integration test? I'm also good in leaving this here in the queue but I won't have time to write the tests for it unfortunately :(
Comment #58
borisson_I'll do a review before tomorrow's hangout for this. We could do this as an experimental module - that sounds like a good idea. Not sure if that's hard do for us.
Congrats on passing tests!
Comment #59
borisson_Happy with the direction here.
Some nitpicks:
I think these should be camel-cased to pass coding standards.
What happens when no id is set? it will return null?
Can we default this to an empty array in the definition instead?
I know this is how the DefaultFacetManager does this - but since then we've learned so much. Would it be better to change this with an array_filter call to reduce complexity?
/s/array/array[]/ to be compatible with the declaration in getFacets?
Let's just point to getFacets instead, this doesn't really add anything to be in there twice and we can only forget to updated one of them if this changes.
Facet summary manager?
I think this is a c/p remnant, should it be updated?
I noticed that building here happens after sorting, we do that the other way around in the defaultFacetManager, any reason?
Same here.
I think this shouldn't be search-api
/s/t(/$this-t(
We've refactored this for the other plugins to be ":","__" as to only have one colon in the plugin id, for consistency with drupal core. Let's change that here as well.
Comment #60
borisson_We should only add tests for the facet-changes for now, other tests can be added as a followup.
getCount is the only actual change - needs thorough testing.
For the experimental module; we should handle this the same way as core handles experimental modules. (package: Facets (Experimental))
Comment #61
borisson_As mentioned, I ran this trough phpcs this is the result.
Comment #62
StryKaizerThis looks great already, thanks all for your work!!
A few nitpicks
- Since #2798483: Move submodules into a modules folder is in, lets move this into the /modules folder
- We probably need processors on this. e.g. when term id's are indexed and transformed into labels using processors in facets, term id's are shown when using "Show a summary of all selected facets".
- Lets set the "empty text behaviour" default disabled. Most usecases will not show anything when there are no filters imo.
- We can probably do with a few less twig templates. Maybe it would also be nice to have the facet machine name (or url identifier) as a class available to group results visualy?
- At this moment there seems to be no support for non-facet queries. D7 also supports search string. Would be nice to have this too.
- Feature request: It would be nice if there's also an option to remove all active filters
Comment #63
borisson_Back to needs work per #62 and #59
Comment #64
mpp CreditAttribution: mpp as a volunteer and at AmeXio commentedWhen enabling the patch and adding a new facet summary, the following warnings occur on 8.2.1:
Also, when displaying the summary block, all facets disappear.
Anyone tested this with search_api_solr yet?
Update: in the UI when unselecting a facet under "ENABLED FACETS" then saving, the facet reappears selected in the list.
Comment #65
borisson_Comment #66
webcultist CreditAttribution: webcultist commentedWhen I create a block in the interface, I receive a white screen with the following error message.
Any idea where this could come from?
Comment #67
borisson_I committed #2813707: Use core's subform state instead of our own. over the weekend - looks like the changes made there don't agree with this patch. This will need a refactor to use core's implementation of subformstate instead of our own old one.
Comment #68
webcultist CreditAttribution: webcultist commentedI don't think that I can help with refactore the module as I'm not deep enough in module development. Is there a way one could help you with this problem?
Comment #69
borisson_I haven't tested the patch, but this should do the refactoring required. (The branch for this issue was 25 commits ago so the rebase might've been a long shot - since the patch size looks similar I have faith git did a good job)
Comment #71
borisson_Fail was unrelated.
Comment #72
borisson_Rebased on the latest changes.
Comment #73
borisson_Moved to subfolder, as discussed.
Comment #75
borisson_Committed this as experimental for now as we discussed.
Comment #76
borisson_Comment #78
borisson_Comment #79
webcultist CreditAttribution: webcultist commentedHave a problem with the summary block, created a new issue for it - does anybody else have that problem? Error when creating a summary block
Comment #81
deepakrmklm CreditAttribution: deepakrmklm at Zyxware Technologies commentedThis works fine. Why it still added as Experimental?
Comment #82
deepakrmklm CreditAttribution: deepakrmklm at Zyxware Technologies commented