Results 1 to 3 of 3

Thread: Add pages with GET parameters to search engine

  1. #1
    New user
    Join Date
    02-14-13.
    Posts
    2

    Default Add pages with GET parameters to search engine

    Hi everyone,

    I apologize in advance for my english, I'm French! :mrgreen:

    I am actually facing a problem with Contao search engine. I developed a module which permits to store detailed product informations and then displays those products on a frontend page. But the issue is that my page needs the product id as a GET parameter. So the URL of my page is like this one:

    mywebsite.com/product-page.html?id=1

    So I wanted that the search engine indexes my product pages. I used the "getSearchablePages" hook like that:

    Code:
    class HookSearchProducts extends Frontend
    {
       public function addProductPages($arrPages, $intRoot=0)
       {
          $objArticle = $this->Database->query("SELECT * FROM tl_produits");
    
          $domain = $this->Environment->base;
    
          while ($objArticle->next())
          {
             $newPages[] = $domain . "fiche-produit/id/" . $objArticle->id . ".html";
          }
    
          $arr =  array_merge($arrPages, $newPages);
    
          return $arr;
       }
    }
    But it doesn't work with this way. When I manually rebuild the search index in the back-office all my product pages are listed correctly, but none of them appears in the "tl_search" table, except the page without the GET parameter.

    However, words of my product pages are correctly indexed. If I search one of the words of my pages, I get a results list where the first result points to the "product-page.html" page (without any GET parameter, which doesn't display my product).

    Is there any way to fix this issue?

    Thanks in advance to those who reflect on my problem.

  2. #2
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: Add pages with GET parameters to search engine

    Try generating your URLs (the ones that are actually click-able in the content of the page) in your custom module in a "friendly" format, e.g.

    mywebsite.com/product-page.html/items/1
    -or-
    mywebsite.com/product-page.html/id/1

    If you aren't using a folder url extension, and if I'm not mistaken Contao will automatically interpret "id" or "items" as a GET parameter and add it to the GET array automatically (as it would for all 2nd-level folders in the URL).

    If you ARE using a folder url extension and want to use "id", you need to add "id" to the $GLOBALS['URL_KEYWORDS'] array (which you can put in your config file).
    Brian

  3. #3
    New user
    Join Date
    02-14-13.
    Posts
    2

    Default Re: Add pages with GET parameters to search engine

    Thank you for your answer. I tried both solutions, but none works as I expect. Even with $GLOBALS['URL_KEYWORDS'] array, I still have the search results pointing to my page without any get parameter. I don't have any idea of what could cause that.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •