# Panel search string content

**URL:** <https://forum.getkirby.com/t/panel-search-string-content/29546>\
**Category:** Questions\
**Tags:** v3\
**Created:** [September 21, 2023, 1:44pm UTC](https://forum.getkirby.com/t/panel-search-string-content/29546 "2023-09-21T13:44:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicolasbulb](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/nicolasbulb/32/1674_2.png) [@nicolasbulb](https://forum.getkirby.com/u/nicolasbulb)\
**Post date:** [September 21, 2023, 1:44pm UTC](https://forum.getkirby.com/t/panel-search-string-content/29546/1 "2023-09-21T13:44:19Z")

</div>

I’m wondering, with the actual Kirby 3.9.x, is it possible in the panel to constrain a search? Like if I want to search for “Colombie”, Kirby is proposing “Colombier” as well but I want to contrain the search to “Colombie” only. Possible?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [September 21, 2023, 2:11pm UTC](https://forum.getkirby.com/t/panel-search-string-content/29546/2 "2023-09-21T14:11:11Z")

</div>

In the frontend, you would limit the search to whole words, to achieve the same, you should could adapt the page view search in a plugin.

---

<div class="post-metadata">

**Author:** ![nicolasbulb](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/nicolasbulb/32/1674_2.png) [@nicolasbulb](https://forum.getkirby.com/u/nicolasbulb)\
**Post date:** [September 21, 2023, 3:53pm UTC](https://forum.getkirby.com/t/panel-search-string-content/29546/3 "2023-09-21T15:53:05Z")

</div>

No, I mean the search in the backend. The one available when in the blueprint this option is set:

```auto
search: true

```

Is it possible to used “” in order to force to search a whole word only?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [September 21, 2023, 3:59pm UTC](https://forum.getkirby.com/t/panel-search-string-content/29546/4 "2023-09-21T15:59:05Z")

</div>

Maybe it did not express myself well.

Kirby has an option to limit search to whole words in the search components, which you can use when you do a front-end search.

In the pages search in the Panel, however, this option is not used and it is not configurable via the blueprint. This is the code from `/kirby/config/areas/site/searches.php`

```auto
		$pages = $kirby->site()
				->index(true)
				->search($query)
				->filter('isListable', true)
				->paginate($limit, $page);

```

The only way to change this is by changing the Panel search:

> **[Panel search](https://getkirby.com/docs/reference/plugins/extensions/panel-search)**

---

<div class="post-metadata">

**Author:** ![timotheegoguely](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/timotheegoguely/32/13657_2.png) [@timotheegoguely](https://forum.getkirby.com/u/timotheegoguely)\
**Post date:** [February 14, 2024, 3:50pm UTC](https://forum.getkirby.com/t/panel-search-string-content/29546/5 "2024-02-14T15:50:34Z")

</div>

Hi, I’m working with @nicolasbulb on this project, and here is what I tried, with no success.

I have this working custom search method `site/plugins/search-method/index.php` and I’m trying to use it inside a Panel search area plugin to only search for full words.

```php
<?php

/**
* Fork of the native $pages->search() method
* Only searches for full matches
*/

function search($collection, $query, $params = array()) {

    if(is_string($params)) {
        $params = array('fields' => str::split($params, '|'));
    }

    $defaults = array(
        'minlength' => 2,
        'fields' => ['title','tags','architect','photographer','publisher','city','country','place','state'],
        'words' => true,
        'score' => array()
    );

    $options = array_merge($defaults, $params);

    if(empty($query)) return $collection->limit(0);

    $results = $collection->filter(function($page) use($query, $options) {
        $data = $page->content()->toArray();
        $keys = array_keys($data);

        if(!empty($options['fields'])) {
            $keys = array_intersect($keys, $options['fields']);
        }

        $page->searchHits = 0;
        $page->searchScore = 0;

        foreach($keys as $key) {
            $score = a::get($options['score'], $key, 1);

            // check for full matches
            if($matches = preg_match_all('!' . preg_quote($query) . '!i', $data[$key], $r)) {
                $page->searchHits += $matches;
                $page->searchScore += $matches * $score;
            }
        }

        return $page->searchHits > 0 ? true : false;
    });

    $results = $results->sortBy('searchScore', SORT_DESC);

    return $results;
}

```

Here is my Panel search area plugin but it doesn’t work as expected, and I don’t understand why.  
`site/plugins/search/index.php`:

```php
<?php

Kirby::plugin('timotheegoguely/search', [
  'areas' => [
    // extending the core search
    'site' => function ($kirby) {
      return [
        'searches' => [
          'pages' => [
            'query' => function (string $query, int $limit = 12) use ($kirby) {

              $collection = $kirby->site()
                ->index(true)
                ->filter('isReadable', true);

              $results = [];
              // I use the custom search method here
              $pages = search($collection, $query)->limit($limit);

              foreach ($pages as $page) {
                $results[] = [
                  'image' => $page->panel()->image(),
                  'text' => Escape::html($page->title()->value()),
                  'link' => $page->panel()->url(),
                  'info' => Escape::html($page->id())
                ];
              }

              // But I didn't get any results....
              return $results;

            }
          ]
        ]
      ];
    },
  ]
]);

```

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [February 14, 2024, 8:13pm UTC](https://forum.getkirby.com/t/panel-search-string-content/29546/6 "2024-02-14T20:13:49Z")

</div>

One thing is certainly that your returned array does not contain the `results` key. Also, it seems that you have to initialize the $kirby variable inside the function, and remove the $kirby parameter from `'site' => function ($kirby) {`.

I would then try if it works if your search function just returns the collection as is. Take a look at the native kirby code as well.
