Skip to content
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

Merged
merged 5 commits into from
Jul 25, 2018

Conversation

nickvergessen
Copy link
Member

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

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

* @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
Member Author

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
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
Member Author

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
Member Author

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
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
Member Author

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
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
Member Author

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
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
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
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
Member Author

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
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.

* @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
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
Copy link

codecov bot commented Apr 19, 2018

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 Files Coverage Δ Complexity Δ
...pps/comments/composer/composer/autoload_static.php 0% <ø> (ø) 1 <0> (ø) ⬇️
lib/public/Search/Provider.php 0% <ø> (ø) 7 <0> (ø) ⬇️
apps/comments/lib/Search/Provider.php 0% <0%> (ø) 10 <10> (?)
lib/private/Comments/Manager.php 90.9% <0%> (+90.9%) 96 <6> (+6) ⬆️
...s/comments/composer/composer/autoload_classmap.php 0% <0%> (ø) 0 <0> (ø) ⬇️
apps/comments/lib/Search/Result.php 0% <0%> (ø) 7 <7> (?)
apps/comments/lib/AppInfo/Application.php 100% <100%> (+100%) 1 <0> (ø) ⬇️
lib/private/Memcache/Redis.php 0% <0%> (-85.72%) 24% <0%> (ø)
lib/private/Files/ObjectStore/Azure.php 0% <0%> (-84.38%) 14% <0%> (ø)
apps/updatenotification/lib/UpdateChecker.php 0% <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
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 nickvergessen force-pushed the feature/noid/search-for-files-by-comments branch 2 times, most recently from 16a35e4 to 686842e Compare April 23, 2018 13:01
@MorrisJobke
Copy link
Member

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

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

🏓

@nextcloud-bot nextcloud-bot removed the stale Ticket or PR with no recent activity label Jun 21, 2018
@nickvergessen nickvergessen force-pushed the feature/noid/search-for-files-by-comments branch from 686842e to a2c03a5 Compare June 25, 2018 13:48
@nickvergessen
Copy link
Member Author

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
Member

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

Yes - #9912

@MorrisJobke
Copy link
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
Member Author

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

@nickvergessen nickvergessen force-pushed the feature/noid/search-for-files-by-comments branch from a2c03a5 to 8fbdab5 Compare July 2, 2018 14:00
@MorrisJobke
Copy link
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
Member Author

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 nickvergessen force-pushed the feature/noid/search-for-files-by-comments branch from 8fbdab5 to 5ea544c Compare July 17, 2018 14:19
@MorrisJobke
Copy link
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
Copy link
Member

MorrisJobke commented Jul 18, 2018

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:

use OCA\Comments\AppInfo\Application;
$app = new Application();

@nickvergessen
Copy link
Member Author

Fixed the code so the constructor is always called.

@MorrisJobke
Copy link
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
Member Author

Anyone with more frontend knowledge volunteering to do that?

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

I will take care of this.

@MorrisJobke MorrisJobke added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Jul 25, 2018
@danxuliu danxuliu force-pushed the feature/noid/search-for-files-by-comments branch from 29078e1 to 3fa4ad4 Compare July 25, 2018 16:36
@danxuliu
Copy link
Member

danxuliu commented Jul 25, 2018

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
Copy link
Member

danxuliu commented Jul 25, 2018

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

nickvergessen and 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 danxuliu force-pushed the feature/noid/search-for-files-by-comments branch from 3fa4ad4 to ac2314e Compare July 25, 2018 16:54
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Copy link
Member

@MorrisJobke MorrisJobke left a comment

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
Member

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

bildschirmfoto 2018-07-25 um 20 28 09

@MorrisJobke
Copy link
Member

In any case, it has my 👍

-> Merging

@MorrisJobke MorrisJobke merged commit 61397ee into master Jul 25, 2018
@MorrisJobke MorrisJobke deleted the feature/noid/search-for-files-by-comments branch July 25, 2018 18:30
@MorrisJobke MorrisJobke added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jul 25, 2018
Sign up for free to 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