Kirby search gives incomplete search result

Hi,

I must say I already asked for help to set up the search results some months ago, but then the project got delayed and only now I am back to it.

I am testing the search function I implemented, and noticed it only works if you put in the search bar words that are part of the title of a page. What I’d like to implement, is to have the search function to scan the whole page and give back results based on all the fields part of a page.

To do that, I took out the second argument in the search function, eg

from

$artworks = $artworks->search($query, 'title|text');

s
to

$artworks = $artworks->search($query);

but still no luck. I got no result back, and var_dump shows that as well.

Here the relevant portion of the search controller.

//++ collection
$collection = $site->children()->findBy('template', 'collection');

//++ artworks
$artworks = $collection->children()->findBy('intendedTemplate', 'artworks')->children()->visible();


//++ search
// return all children if nothing is selected
$query = get('q');

if($query) {
  $artworks = $artworks->search($query);
}

$artworks = $artworks->paginate(20);
$pagination = $artworks->pagination();

How to go on this?

Thanks, af

May I asked what your setup is? Is search a separate page with its own controller and template?

If you don’t pass any arguments, all fields are searched. I thought we got it working back then in the other thread?

Search is its own page w/ controller and template, but I setup also filter-by-tag in the same page—I don’t think it should interfere though.

In the other thread I was still using

$artworks = $artworks->search($query, 'title|text');

so then it was just looking for those two fields, right?

Now I set it to

$artworks = $artworks->search($query);

but it only work for the title field.

Can I provide more informations?

That is strange. The native search method searches through all fields. You can test this in a starterkit like this:

In your home.php template, put this code:

$query = get('q');
$results = $site->index()->search($query);
dump($results);

Then call your homepage with the q parameter, e.g. like this:

https://example.com?q=2013

Result should be:

Children Object
(
    [0] => projects/project-b
    [1] => projects/project-d
)

(where the year is stored in the year field, not title or text)

Question: if you call your search page without any parameter, what result do you get?

Your test worked like a charm indeed.

If I don’t search for some value, I simply get all the results—all the children of that page.

My kirby is updated to the latest version. I’ll take another peek at it, to see if I have missed something.

Can you give me an example of a search word that does not give you any results? And which pages that search word should reveal as a result and why? I.e. where the information is in your content file and in what sort of context?

Sure

Current folder structure:

content/
collection/
artworks/
artwork-name/
artwork.txt

Blueprint

Title: Artwork #12

----

Text: blabaha

----

Author: Edoardo Belli

----

Size: 33 x 24 cm

----

T: Arte astratta

----

Year: 2012

----

Bio: ALKAlakalaklakalakalakalaka

----

Location: XXXXXX

and

fields:
  title:
    label: Titolo
    type:  text
  author:
    label: Autore
    type: select
    options: query
    query:
      page: ../../autore
      fetch: children
      value: '{{title}}'
  year:
    label: Anno
    type: text
    width: 1/2
  size:
    label: Dimensioni
    type: text
    width: 1/2
  t:
    label: Tecnica
    type: tags
  location:
    label: Luogo
    type: select
    options: query
    query:
      page: luoghi
      fetch: grandchildren
      value: '{{title}}'

I can look up for 2012, Arta Astratta, Edoardo and get no result back. If I type Artwork I get all the list of pages containing Artwork in their title.

Is that site online somewhere?

Yes, this the search page → http://work.andrefincato.info/artoteca_beta/catalogo

github repo → https://github.com/afincato/artoteca.bz

The repo still has the restriction to the title and text fields, are you sure you have changed the online version? I can’t make tests with the repo cause no content.

I blame having a fever for the fact that I thought I took out the second value after $query in here

$artworks = $artworks->search($query, 'title|text');

as I did in fact, but on the wrong and very similar controller.php.

ty! working now!