Skip to content

Adding search files functionality in Paperless from Nextcloud#49

Open
Jin-Di wants to merge 23 commits intonextcloud:mainfrom
Jin-Di:feature/add-search-function-for-nextcloud
Open

Adding search files functionality in Paperless from Nextcloud#49
Jin-Di wants to merge 23 commits intonextcloud:mainfrom
Jin-Di:feature/add-search-function-for-nextcloud

Conversation

@Jin-Di
Copy link

@Jin-Di Jin-Di commented Dec 13, 2024

#10. Adding search files functionality in Paperless from Nextcloud. The function is similar from Zulip's integration.

@Jin-Di Jin-Di force-pushed the feature/add-search-function-for-nextcloud branch from e8cab4f to 6ad6b89 Compare December 13, 2024 06:34
@provokateurin
Copy link
Member

Thanks for your PR, I will take a look next week!

Copy link
Member

@provokateurin provokateurin left a comment

Choose a reason for hiding this comment

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

The indentation is very inconsistent, please fix by running composer cs:fix

Copy link
Member

Choose a reason for hiding this comment

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

This looks very much like you copied it from another integration app without the appropriate copyright.
I'm not a fan of this code, but you have to at least add the copyright of the original authors.

Copy link
Member

Choose a reason for hiding this comment

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

This makes no sense, there is no route to this controller method and the frontend never tries to call any API

Copy link
Member

Choose a reason for hiding this comment

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

Changing the frontend dependencies is not necessary at all.
You're also adding some new ones that are never used.

Copy link
Member

Choose a reason for hiding this comment

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

Revert this as well.

Comment on lines 88 to 114
public function request(string $userId, string $endPoint, array $params = [], string $method = 'GET',
bool $jsonResponse = true, bool $paperlessApiRequest = true) {
return $this->networkService->request($userId, $endPoint, $params, $method, $jsonResponse, $paperlessApiRequest);
}
Copy link
Member

Choose a reason for hiding this comment

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

Please don't do this and add the NetworkService.
You can just implement the call directly like it is done in sendFile().

Comment on lines 83 to 85
// Sort by most recent
// $messages = array_reverse($result['document'] ?? []);
return array_slice($result, $offset, $limit);
Copy link
Member

Choose a reason for hiding this comment

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

This endpoint seems to use pagination, so that needs to be implemented for the offset and limit to work properly.

$formattedResults = array_map(function (array $entry) use ($url): SearchResultEntry {
$finalThumbnailUrl = $this->getThumbnailUrl($entry);
$title = $entry['title'] ?? 'Untitled';
$context = $entry['__search_hit__']['highlights'] ?? '';
Copy link
Member

Choose a reason for hiding this comment

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

I think this can return HTML (see https://docs.paperless-ngx.com/api/#searching-for-documents), so the result will be quite ugly because it will not be rendered.

Copy link
Author

Choose a reason for hiding this comment

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

May I know which one does you mean?

Copy link
Member

Choose a reason for hiding this comment

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

image
This contains raw HTML

Copy link
Author

@Jin-Di Jin-Di Dec 18, 2024

Choose a reason for hiding this comment

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

The strip_tags function at the return will remove the HTML tag, so it won't return any raw HTML.

Copy link
Member

Choose a reason for hiding this comment

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

Ah my bad I didn't see that. Can you already call it when initializing the variable? I feel like it is harder to miss then.

$title,
strip_tags($context),
$link,
$finalThumbnailUrl === '' ? 'icon-paperless-search-fallback' : '',
Copy link
Member

Choose a reason for hiding this comment

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

This fallback icon doesn't exist

Copy link
Author

Choose a reason for hiding this comment

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

I think I mislook on this one, will remove it since I don't think thumbnail is required.

* @return string
*/
protected function getThumbnailUrl(array $entry): string {
return '';
Copy link
Member

Choose a reason for hiding this comment

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

Not implemented?

Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
…original authors

Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
…in sendFile().

Remove the NetworkService.php

Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
@Jin-Di Jin-Di force-pushed the feature/add-search-function-for-nextcloud branch from a9ad6b1 to 49254f7 Compare December 18, 2024 03:35
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
@Jin-Di
Copy link
Author

Jin-Di commented Dec 18, 2024

I have fixed issues above, please check @provokateurin.

Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
Copy link
Member

@provokateurin provokateurin left a comment

Choose a reason for hiding this comment

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

Have you tried running this code against a paperless-ngx instance? I doubt that currently works at all because it doesn't even parse the output correctly.

'headers' => array_merge(
$this->getAuthorizationHeaders(),
[
'Content-Type' => 'application/json',
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
'Content-Type' => 'application/json',

You're not actually sending any data in the body, so this is not correct

Comment on lines 91 to 92
$paperlessURL = rtrim($this->config->url, '/') . '/api/documents/?' . http_build_query($arguments);
$result = $this->client->get($paperlessURL,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$paperlessURL = rtrim($this->config->url, '/') . '/api/documents/?' . http_build_query($arguments);
$result = $this->client->get($paperlessURL,
$result = $this->client->get($this->config->url . '/api/documents/?' . http_build_query($arguments),

Just do it like in the sendFile() method. Trimming is not necessary

Copy link
Author

Choose a reason for hiding this comment

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

Just my two cents here. I think users usually input the URL including a trailing slash, especially when they copy-paste them from documentation or browser address bars. This was also one of the issues I faced when testing the code, as I didn't realize that I have a trailing slash behind the URL entered. So, this approach will reduce the chances of errors caused by duplicate slashes or incorrect URLs. Let me know your final decision on which approach you'd like to go with.

Comment on lines 107 to 109
if (isset($json_body['error'])) {
return (array)$json_body;
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't see anything like this in the API docs. Please check in the source code of paperless-ngx how an error response will look like and adjust it here.

Copy link
Author

Choose a reason for hiding this comment

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

I don't find any explicit error key in the API responses. However, I noticed that the API returns an HTML response when the URL is incorrect.

So, I’m checking for an HTML key in the JSON. Let me know if you have different ideas.

* This file contains code derived from Nextcloud - Zulip
* @copyright Copyright (c) 2024, Edward Ly
*
* @author Edward Ly <contact@edward.ly>
Copy link
Member

Choose a reason for hiding this comment

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

Also add yourself to this authors list

Copy link
Member

Choose a reason for hiding this comment

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

This Controller is still not used at all, please remove it

Copy link
Author

Choose a reason for hiding this comment

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

My bad, I mislooked.

Jin-Di and others added 16 commits December 19, 2024 10:29
Co-authored-by: Kate <26026535+provokateurin@users.noreply.github.com>
Signed-off-by: Jin-Di <jdgoh334@gmail.com>
Co-authored-by: Kate <26026535+provokateurin@users.noreply.github.com>
Signed-off-by: Jin-Di <jdgoh334@gmail.com>
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
…m:Jin-Di/integration_paperless into feature/add-search-function-for-nextcloud
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
Co-authored-by: Kate <26026535+provokateurin@users.noreply.github.com>
Signed-off-by: Jin-Di <jdgoh334@gmail.com>
Co-authored-by: Kate <26026535+provokateurin@users.noreply.github.com>
Signed-off-by: Jin-Di <jdgoh334@gmail.com>
…m:Jin-Di/integration_paperless into feature/add-search-function-for-nextcloud
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
Signed-off-by: Goh Jin Di <jdgoh334@gmail.com>
@Jin-Di
Copy link
Author

Jin-Di commented Dec 23, 2024

I think the pagination is fixed, please check @provokateurin. I believe the Unified Search result is limited to 25 by default. It is hardcoded in the application, the way I exceed it is modifying the code in core/Controller/UnifiedSearchController.php. I didn't find other workarounds, so maybe it is intended to be max 25?

@github-actions
Copy link

Hello there,
Thank you so much for taking the time and effort to create a pull request to our Nextcloud project.

We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process.

Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6

Thank you for contributing to Nextcloud and we hope to hear from you soon!

(If you believe you should not receive this message, you can add yourself to the blocklist.)

@pktiuk
Copy link

pktiuk commented Oct 1, 2025

@provokateurin

What is this PR waiting for?

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.

3 participants