Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jQuery was updated to v2.2. The most notable change is that ``$(document).ready(
Search
******

The unified search replaces the traditional search input, hence ``OCA.Search`` became a noop. For backwards compatibility, the code will not raise any errors now, but it does not have any functionality.
The :ref:`unified search<unified-search>` replaces the traditional search input, hence ``OCA.Search`` became a noop. For backwards compatibility, the code will not raise any errors now, but it does not have any functionality.

Removed globals
***************
Expand Down
42 changes: 22 additions & 20 deletions developer_manual/digging_deeper/search.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _unified-search:

======
Search
======
Expand Down Expand Up @@ -168,26 +170,9 @@ Handling search requests

Search requests are processed in the ``search`` method. The ``$user`` object is the user who the result shall be generated for. ``$query`` gives context information like the **search term**, the **sort order**, the **route information**, the **size limit** of a request and the **cursor** for follow-up request of paginated results.

The result is encapsulated in the ``SearchResult`` class that offers two static factory methods ``complete`` and ``paginated``. Both of these methods take an array of ``SearchResultEntry`` objects. ``SearchResultEntry`` is a static class that can be extended and used by the provider.

.. note:: In most cases you don't have to add any methods or fields to this new result entry type so you can directly use ``SearchResultEntry``, but this API design was chosen so new optional properties can be added in the future without breaking the existing implementations in 3rd party apps.

.. code-block:: php

<?php

declare(strict_types=1);

namespace OCA\MyApp\Search;

use OCP\Search\SearchResultEntry;

class MySearchResultEntry extends SearchResultEntry {}


The above snippet shows this implementation of a result entry. Again, this class should be saved to ``lib/Search`` in the app directory.
The result is encapsulated in the ``SearchResult`` class that offers two static factory methods ``complete`` and ``paginated``. Both of these methods take an array of ``SearchResultEntry`` objects.

Next, you'll see a dummy provider that returns a static set of results using the result entry class from above.
Next, you'll see a dummy provider that returns a static set of results.

.. code-block:: php

Expand All @@ -202,6 +187,7 @@ Next, you'll see a dummy provider that returns a static set of results using the
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\Search\IProvider;
use OCP\Search\SearchResultEntry;

class Provider implements IProvider {

Expand Down Expand Up @@ -238,7 +224,7 @@ Next, you'll see a dummy provider that returns a static set of results using the
return SearchResult::complete(
$this->l10n->t('My app'),
[
new MySearchResultEntry(
new SearchResultEntry(
$this->urlGenerator->linkToRoute(
'myapp.Preview.getPreviewByFileId',
[
Expand Down Expand Up @@ -410,3 +396,19 @@ For a **cursor-based pagination** a app-specific property is used to know a refe
);
}
}

Optional attributes
^^^^^^^^^^^^^^^^^^^

The unified search is available via OCS, which means client application like the mobile apps can use it to get access to the server search mechanism. The default properties of a search result entry might be difficult to parse and interpret in those clients, hence it's possible to add optional string attributes to each entry.

.. code-block:: php

<?php

$entry = new SearchResultEntry(/* same arguments as above */);
$entry->addAttribute("type", "deckCard");
$entry->addAttribute("cardId", "1234");
$entry->addAttribute("boardId", "567");

.. note:: This method was added in Nextcloud 21. If your app also targets Nextcloud 20 you should either not use it or add a version check to invoke the method only conditionally.