Skip to content

Allow to search files by comments - #9222

Merged
MorrisJobke merged 5 commits into
masterfrom
feature/noid/search-for-files-by-comments
Jul 25, 2018
Merged

Allow to search files by comments#9222
MorrisJobke merged 5 commits into
masterfrom
feature/noid/search-for-files-by-comments

Conversation

@nickvergessen

Copy link
Copy Markdown
Member

bildschirmfoto von 2018-04-18 11-25-26

PS: this is an accident, I was just preparing search for chat messages in talk.

Comment threadlib/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 {

Copy link
Copy Markdown
MemberAuthor

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?

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
MemberAuthor

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 💃

Copy link
Copy Markdown
MemberAuthor

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.

Copy link
Copy Markdown
Member

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;

Copy link
Copy Markdown
MemberAuthor

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 {

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
MemberAuthor

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.

Copy link
Copy Markdown
Member

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,

Copy link
Copy Markdown
Member

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();

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
MemberAuthor

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') {

Copy link
Copy Markdown
Member

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.

Comment threadlib/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 {

Copy link
Copy Markdown
Member

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

codecovBot commented Apr 19, 2018

Copy link
Copy Markdown

Codecov Report

Merging #9222 into master will increase coverage by 28.21%.
The diff coverage is 1.01%.

@@ 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
Impacted FilesCoverage ΔComplexity Δ
...pps/comments/composer/composer/autoload_static.php0% <ø> (ø)1 <0> (ø)⬇️
lib/public/Search/Provider.php0% <ø> (ø)7 <0> (ø)⬇️
apps/comments/lib/Search/Provider.php0% <0%> (ø)10 <10> (?)
lib/private/Comments/Manager.php90.9% <0%> (+90.9%)96 <6> (+6)⬆️
...s/comments/composer/composer/autoload_classmap.php0% <0%> (ø)0 <0> (ø)⬇️
apps/comments/lib/Search/Result.php0% <0%> (ø)7 <7> (?)
apps/comments/lib/AppInfo/Application.php100% <100%> (+100%)1 <0> (ø)⬇️
lib/private/Memcache/Redis.php0% <0%> (-85.72%)24% <0%> (ø)
lib/private/Files/ObjectStore/Azure.php0% <0%> (-84.38%)14% <0%> (ø)
apps/updatenotification/lib/UpdateChecker.php0% <0%> (ø)8% <0%> (-2%)⬇️
... and 647 more

* @return IComment[]
* @since 14.0.0
*/
public function search(string $search, string $objectType, string $objectId, string $verb): array;

Copy link
Copy Markdown
Member

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

@nickvergessen
nickvergessenforce-pushed the feature/noid/search-for-files-by-comments branch 2 times, most recently from 16a35e4 to 686842eCompareApril 23, 2018 13:01
@MorrisJobke

Copy link
Copy Markdown
Member

It doesn't find the comments for me - it also never gets into the search provider of comments when adding a breakpoint there :/

@MorrisJobkeMorrisJobke added the stale Ticket or PR with no recent activity label Jun 19, 2018
@MorrisJobke

Copy link
Copy Markdown
Member

🏓

@nextcloud-botnextcloud-bot removed the stale Ticket or PR with no recent activity label Jun 21, 2018
@nickvergessen
nickvergessenforce-pushed the feature/noid/search-for-files-by-comments branch from 686842e to a2c03a5CompareJune 25, 2018 13:48
@nickvergessen

Copy link
Copy Markdown
MemberAuthor

Fixed searching, however the results are not looking like the screenshot anymore.
Was there a major redesign/refactoring of the search result design?

@MorrisJobke

Copy link
Copy Markdown
Member

Was there a major redesign/refactoring of the search result design?

Yes - #9912

@MorrisJobke

Copy link
Copy Markdown
Member

The search itself doesn't work for me. I shared a file with another user and both commented with:

Lorem ipsum dolor sit amet, consectetur, adipisci velit

Searching then for Lorem does not show any search result. It was on a file. Anything that I miss?

@nickvergessen

Copy link
Copy Markdown
MemberAuthor

I just rebased and tested this again: works pretty fine here for both the sharer and the sharee

@nickvergessen
nickvergessenforce-pushed the feature/noid/search-for-files-by-comments branch from a2c03a5 to 8fbdab5CompareJuly 2, 2018 14:00
@MorrisJobke

Copy link
Copy Markdown
Member

Doesn't show anything for me on this branch (left is heinz, right is admin, both commented with a string that is then searched for):

bildschirmfoto 2018-07-05 um 12 00 34

What do I do wrong?

@nickvergessen

Copy link
Copy Markdown
MemberAuthor

So the entry point is

$results = $this->searcher->searchPaged($query, $inApps, $page, $size);

Once I step into that, after the init method, I can see this->providers containing the new OCA\Comments\Search\Provider:
$this->initProviders();

And from there on the debugger should be able to step through and show you where you are leaving the trail

@nickvergessen
nickvergessenforce-pushed the feature/noid/search-for-files-by-comments branch from 8fbdab5 to 5ea544cCompareJuly 17, 2018 14:19
@MorrisJobke

Copy link
Copy Markdown
Member

Once I step into that, after the init method, I can see this->providers containing the new OCA\Comments\Search\Provider:

For me that was not the case 😢

bildschirmfoto 2018-07-18 um 09 30 54

@MorrisJobke

MorrisJobke commented Jul 18, 2018

Copy link
Copy Markdown
Member

The constructor of the class OCA\Comments\AppInfo\Application is never called. I needed to actively instantiate it in the app.php of the comments app. Then the provider is properly loaded but the UI is still broken:

bildschirmfoto 2018-07-18 um 09 39 43

bildschirmfoto 2018-07-18 um 09 39 57

I added this to the app.php:

useOCA\Comments\AppInfo\Application;
$app = newApplication();

@nickvergessen

Copy link
Copy Markdown
MemberAuthor

Fixed the code so the constructor is always called.

@MorrisJobke

Copy link
Copy Markdown
Member

it still looks like that and the path and the avatar is not set properly:

bildschirmfoto 2018-07-18 um 17 51 29

@nickvergessen

Copy link
Copy Markdown
MemberAuthor

Anyone with more frontend knowledge volunteering to do that?

@MorrisJobkeMorrisJobke mentioned this pull request Jul 24, 2018
21 tasks
Signed-off-by: Joas Schilling <coding@schilljs.com>
@danxuliu

Copy link
Copy Markdown
Member

I will take care of this.

@MorrisJobkeMorrisJobke added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Jul 25, 2018
@danxuliu
danxuliuforce-pushed the feature/noid/search-for-files-by-comments branch from 29078e1 to 3fa4ad4CompareJuly 25, 2018 16:36
@danxuliu

danxuliu commented Jul 25, 2018

Copy link
Copy Markdown
Member

I have rebased on master and made the following changes:

  • Moved the last commit to the first one
  • Squashed the fixes into the commits that they fixed
  • Restored the return type in the documentation of OCP\Search\Provider::search from Result[] to array (of course feel free to add it back, but please modify it everywhere, not just in the base class leaving all the subclasses dangling with the old type ;-) )
  • Fixed duplicated search results (for some reason, that I have not digged into, the application is created twice; as the provider was registered in the constructor it was registered twice and results were duplicated; now the provider is registered in register())
  • Fixed search before pagination was introduced (the parameters were passed in wrong order to $cm->search, and users should be passed to resolveDisplayName)
  • Fixed UI (the plugin now has to be registered with OCA.Search.Core instead of OCA.Search)
  • Renamed renderFileResult and handleFileClick to renderCommentResult and handleCommentClick (nitpicking, the name should refer to the type of the result)
  • Added integration tests (no time for unit or acceptance tests, sorry ;-) )

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:

  • The link to the file is not included in the search results
  • The name property in the result includes the full comment, without ellipsis; I have no idea if that is right or not. In any case the UI shows the ellipsized version.

@danxuliu

danxuliu commented Jul 25, 2018

Copy link
Copy Markdown
Member

Ok, give me a second, I made a stupid change... :P Done.

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

nickvergessenand others added 3 commits July 25, 2018 18:53
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>
@danxuliu
danxuliuforce-pushed the feature/noid/search-for-files-by-comments branch from 3fa4ad4 to ac2314eCompareJuly 25, 2018 16:54
Signed-off-by: Morris Jobke <hey@morrisjobke.de>

@MorrisJobkeMorrisJobke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and works 👍

@MorrisJobke

Copy link
Copy Markdown
Member

I just made the icon brighter (top before, bottom after):

bildschirmfoto 2018-07-25 um 20 28 09

@MorrisJobke

Copy link
Copy Markdown
Member

In any case, it has my 👍

-> Merging

@MorrisJobke
MorrisJobke merged commit 61397ee into masterJul 25, 2018
@MorrisJobke
MorrisJobke deleted the feature/noid/search-for-files-by-comments branch July 25, 2018 18:30
@MorrisJobkeMorrisJobke added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jul 25, 2018
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@nickvergessen@MorrisJobke@danxuliu@blizzz@skjnldsv@nextcloud-bot