Search Results Not Showing Duplicate Titles

When doing a search from csv file, the results do not show the duplicate items.

Controller

<?php

return function ($site) {

  $query   = get('q');
  $results = page('products')->search($query, 'title|text|description|cost|vendor');
  
  return [
    'query'      => $query,
    'results'    => $results,
  ];

};

CSV Titles
Screenshot 2023-05-09 at 4.48.54 PM

Results

Okay, I think its not the search actually. It’s the page model for reading the CSV file. How can I update to show duplicates?

<?php

class ProductsPage extends Page
{

    public function children()
    {
        $csv      = csv($this->root() . '/priceapppricing.csv', ',');
        $children = array_map(function ($product) {
            return [
                'slug'     => Str::slug($product['Title']),
                'template' => 'product',
                'model'    => 'product',
                'num'      => 0,
                'content'  => [
                    'title'       => $product['Title'],
                    'description' => $product['DESCRIPTION'],
                    'cost' => $product['COST'],
                    'vendor' => $product['Vendor'],
                    'sixtypercent' => $product['Sixty Percent'],
                    'sixtysixpercent' => $product['Sixty Six Percent'],
                    'seventyonepercent' => $product['Seventy One Percent'],
                    'seventyfivepercent' => $product['Seventy Five Percent'],
                    'controlrange' => $product['Control Range'],
                    'doserate' => $product['Dose Rate'],
                    'dosagepergallons' => $product['Dosage Per 1,000 Gallons'],
                    'primaryingredients' => $product['Primary Ingredients'],
                    'costrevision' => $product['Cost Revision'],
                    'controlparameter' => $product['Control Parameter'],
                ]
            ];
        }, $csv);

        return Pages::factory($children, $this);
    }

}

This has to do with the virtual pages being created and the urls are the same on the duplicate products. So what is happening is that it is going over the array and using the second one it finds as you cannot have two pages with the same url.

i.e. /products/1015-005 and /products/1015-005

Exactly, the slug always has to be unique

1 Like

@texnixe Thanks, I’m really getting the hang of all of Kirby now. I ended up using

'slug'     => Str::slug($product['Title']."-".$product['Vendor']),

In case anyone is wondering how to add other page variables with concatenation.