There are some changes to search query functionality (apart from #2044133: Support replacing the query class) which have been requested over the years and which I think would be sensible to include in a new branch, like the module's D8 version. In no particular order:
- Move the parse mode out of the normal options and into its own field. That would enable changing if after keys were set, for example. It's not a normal option anyways, since service classes don't have to read it anyways.
- Make conditions
Condition class instances (and create that class, plus interface) instead of magic arrays with three ordered properties.
- It would be useful and make sense to have a common base interface for both filters and queries, like it's already done in the DB layer.
- Also stolen from the DB layer: give search queries tags and provide
hook_search_api_query_TAG_alter().
- Rename filters to "condition groups" so it's (hopefully) clearer what they do.
Estimated Value and Story Points
This issue was identified as a Beta Blocker for Drupal 8. We sat down and figured out the value proposition and amount of work (story points) for this issue.
Value and Story points are in the scale of fibonacci. Our minimum is 1, our maximum is 21. The higher, the more value or work a certain issue has.
Value : 13
Story Points: 21
Comments
Comment #1
drunken monkeyAlso, is anyone really using the
performancekey of results?Comment #2
drunken monkeyAdded that the query interface should extend the filter interface.
Comment #3
drunken monkeyComment #4
drunken monkeyTags and metadata for queries would also be nice to have, I guess?
What other ideas are there that we can steal from the DB layer?
Comment #5
drunken monkeyReading #2174049: Exposed form filter with multiple textfields doesn't return correct results and several similar issues/questions in the past, I don't think the current definition/implementation of conditions on fulltext fields make sense. They should just be treated as fulltext keywords for just that field (without influencing the relevance, though, of course), I'd say, with the normal parsing executed on it (probably just like the one for "direct" parse mode).
Comment #6
drunken monkeyfields()andsort(), but not forcondition(). (If we want to check there, too, the filter needs to be aware of the index, though – but that might make sense in any case.) Either we should check in all the methods, where it makes sense, or just once inexecute()(would eliminate the possibility that other methods throw exceptions – probably a DX plus), or completely leave that to the service classes (bad UX because of code duplication).Conditionclass instances (and create that class, plus interface) instead of magic arrays with three ordered properties.Comment #7
drunken monkeyI was sure I had already mentioned that somewhere, but can't find it at the moment: Parse modes should be proper plugins in D8, not hard-coded into the query class (from which they can be used completely independently, I think).
Comment #8
drunken monkeyAdded the idea from #2271709: Add a new "verbatim" equality operator.
Comment #9
drunken monkeyAdded open question regarding the "parse mode" to use for fulltext conditions.
Comment #10
nick_vhComment #11
nick_vhComment #12
drunken monkeyMoved some tasks to child issue and removed others. The remaining issues should be solved with the attached patch.
Please test/review!
Comment #13
borisson_Overall this looks great and I think this is almost ready, I found a couple small nitpicks though
I would rephrase this comment: "Exclude the node with ID 10 from being indexed."
This example code is confusing, because we're already in the example code for a
_TAG_query alter, I'd remove these lines.Can we also use the comment suggested in .1 here?
The indenting here is different compared to
hook_search_api_query_alter, we should use the same style in both functions.Can we refactor this
$condvariable to be$condition?I'd prefer the added readability over the saved bytes.
Can we refactor this
$cvariable to be$condition?I'd prefer the added readability over the saved bytes.
This is a lot more readable, awesome!
Should we use
is_nullinstead?Can we create a new issue and link to that issue from the code or should we fix this in this issue?
Should we change this comment as well?
80 cols.
should this be "conditions"?
Can we explain why this is by reference in the comment?
Is this still filters or should this be conditions?
Can we document why this is by reference?
Should we change this to
testProcessConditions?This looks a lot better, ++.
Should this message be "Conditions were preprocessed correctly"?
See previous comments.
Comment #14
borisson_Also, if #2625264: Add tests for the module's alter hooks lands first, this needs an extra test for firing the tag hook.
Comment #15
drunken monkeyOh, wow. Now I know how everyone else always feels with me. ;)
Thanks a lot for the detailed review, you are truly a master of picking the nit! We should get together sometime, grab a larger Core issue and do a "Nitpicking Battle".
(Just to avoid misunderstandings: I'm truly greatful for the review. Finally someone who cares about coding style and can help me keep the module in order.)
Anyways, a few comments to your comments:
It's not "being indexed", it's "the search results" – but otherwise, agreed, seems sensible. Even if it can be multiple search items, it's still a single node, and implying something different will only confuse people.
But you cannot use the
_TAG_hook to run for all searches except those with a specific tag. For that, you'd need a line such as that one.On the other hand, though, I guess it also doesn't really add to the example, so we might as well remove it, if you are unsure about it.
Pretty sure my IDE did that on its own (wish I knew how to stop it), thanks for spotting!
No, we can't, if we rename
$condto the same. ;)But I think I came up with an even better solution.
I guess there isn't even really a reason to have the comment there, I just created an issue for it: #2631828: Make database OR facets more robust and performant. It's not in any way important, I'd say, so we can just leave it for now (and probably longer, unless someone complains or is interested enough).
I think in this case "filters" is OK, since it talks more about a general principle than something Search API-specific – a query without keywords. Also, "conditions-only query" sounds weird.
Otherwise, just thanks for the thorough review! I hope the attached patch fixes all of that.
Comment #16
borisson_Awesome. Very happy with your answers and the changed code, I'd say this is RTBC.
Comment #17
drunken monkeyGreat, thanks again for your reviews!
Committed.