-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to search files by comments #9222
Allow to search files by comments #9222
Conversation
lib/private/Comments/Manager.php
Outdated
* @param string $verb Limit the verb of the comment | ||
* @return IComment[] | ||
*/ | ||
public function search(string $search, string $objectType, string $objectId, string $verb): array { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we should add an limit/offset here, opinions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can lead to pretty big requests, yes.
Is this an admin only tool?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's the normal search in the top right, which finds files for you 💃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with pagination is, we paginate the comments. Afterwards we need to look if the user can actually see the file where the comment lives. so while we paginate, the page could still be empty, unless we loop until we found enough comments....
But offset is pretty hard with that, so maybe we don't go for offset at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A limit certainly makes sense. Pagination is hairy without a reliable offset. This is not solved in LDAP either, there you also need to start to start from scratch. So this needs some extra handling, and is costly of course… unless here if there is a possibility to know the last item from the previous batch. Then you could it's timestamp and id as starting point. Usually you don't and tracking this over requests is cumbersome. Fake pagination with retrieving more results than shown (also as follow-up request) can be a dirty work around.
The other approach would be having very specialized search implementations that do the permission checks within the same DB query.
$suffix = '…'; | ||
} | ||
|
||
return $prefix . substr($message, $start, $end - $start) . $suffix; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is rather arbitrary atm, we could also search for the beginning/end of the next word and if it is within the range cut there. On the other hand I like simplicity
use OCP\Files\NotFoundException; | ||
use OCP\Search\Result; | ||
|
||
class CommentSearchResult extends Result { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Comment and Search are already present in the namespace, calling the class Result would suffice. The Comment's Manager is also just called Manager. And the new Provider is also just Provider. It's not that I care too much about the naming, but perhaps we should go to a consistent scheme, which ever it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just used a more specific one because Result would conflict with the extend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be imported under an alias or using full name space. anyway, not that important.
* @param string $path | ||
* @throws NotFoundException | ||
*/ | ||
public function __construct(string $search, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing the IComment would reduce at least 2 parameters and be more flexible to whatever in the future (e.g. when taking the author type into consideration).
* @since 7.0.0 | ||
*/ | ||
public function search($query): array { | ||
$cm = \OC::$server->getCommentsManager(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing DI is due to legacy around search infrastructure I guess?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah new $class($options)
prevents decent DI…
|
||
$result = []; | ||
foreach ($comments as $comment) { | ||
if ($comment->getActorType() !== 'users') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the limitation? If it is about the displayName , the Comments Manager can resolve them.
lib/private/Comments/Manager.php
Outdated
* @param string $verb Limit the verb of the comment | ||
* @return IComment[] | ||
*/ | ||
public function search(string $search, string $objectType, string $objectId, string $verb): array { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A limit certainly makes sense. Pagination is hairy without a reliable offset. This is not solved in LDAP either, there you also need to start to start from scratch. So this needs some extra handling, and is costly of course… unless here if there is a possibility to know the last item from the previous batch. Then you could it's timestamp and id as starting point. Usually you don't and tracking this over requests is cumbersome. Fake pagination with retrieving more results than shown (also as follow-up request) can be a dirty work around.
The other approach would be having very specialized search implementations that do the permission checks within the same DB query.
Codecov Report
@@ Coverage Diff @@
## master #9222 +/- ##
=============================================
+ Coverage 6.37% 34.58% +28.21%
+ Complexity 26228 26128 -100
=============================================
Files 1673 1653 -20
Lines 96950 96494 -456
Branches 1290 1290
=============================================
+ Hits 6184 33376 +27192
+ Misses 90766 63118 -27648
|
* @return IComment[] | ||
* @since 14.0.0 | ||
*/ | ||
public function search(string $search, string $objectType, string $objectId, string $verb): array; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FakeManager in Tests needs to implement this as well
16a35e4
to
686842e
Compare
It doesn't find the comments for me - it also never gets into the search provider of comments when adding a breakpoint there :/ |
🏓 |
686842e
to
a2c03a5
Compare
Fixed searching, however the results are not looking like the screenshot anymore. |
Yes - #9912 |
The search itself doesn't work for me. I shared a file with another user and both commented with:
Searching then for |
I just rebased and tested this again: works pretty fine here for both the sharer and the sharee |
a2c03a5
to
8fbdab5
Compare
So the entry point is
Once I step into that, after the init method, I can see this->providers containing the new OCA\Comments\Search\Provider: Line 49 in 21a720e
And from there on the debugger should be able to step through and show you where you are leaving the trail |
8fbdab5
to
5ea544c
Compare
The constructor of the class I added this to the use OCA\Comments\AppInfo\Application;
$app = new Application(); |
Fixed the code so the constructor is always called. |
Anyone with more frontend knowledge volunteering to do that? |
Signed-off-by: Joas Schilling <coding@schilljs.com>
I will take care of this. |
29078e1
to
3fa4ad4
Compare
I have rebased on master and made the following changes:
All in all just minor changes; besides the integration tests the bulk of the pull request is still the same (and I have not modified nor tested the pagination). In any case, it has my 👍 Some details:
|
What have we learned, kids? Yes, you do not see a parameter without type and think Oh, let's add the missing type and push, no need to test, it is just a minor change and everything will be fine :-P |
Signed-off-by: Joas Schilling <coding@schilljs.com>
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Signed-off-by: Joas Schilling <coding@schilljs.com>
3fa4ad4
to
ac2314e
Compare
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and works 👍
-> Merging |
PS: this is an accident, I was just preparing search for chat messages in talk.