Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Why do you want to build the index every day?

    Thread Starter informaticaesporien

    (@ifoesporien)

    Hi Mikko, I upload the products via an external program and unless you click on build index manually it doesn’t index the new products.

    Plugin Author Mikko Saari

    (@msaari)

    How many products you upload at once? How big is your product database? Are the older products modified?

    It might be possible to adjust the process so that the new products are indexed as they are added, which would remove the need to reindex posts that are already indexed. But if old products are modified too, then reindexing everything is better.

    If you use the WooCommerce API, the solution is this simple:

    add_action(
      'woocommerce_new_product',
      function( $id ) {
        relevanssi_index_doc( $id, true, relevanssi_get_custom_fields(), true );
      }
    );

    This will ensure all new products are indexed.

    Thread Starter informaticaesporien

    (@ifoesporien)

    It depends on the day. I have thousands of products. Yes, older products are also modified. I wanted to index every day even if no products have been created or modified. Is it possible to program an action that executes the relevanssi_build_index() function every day?

    Plugin Author Mikko Saari

    (@msaari)

    Yes. That’s the basic idea: run relevanssi_build_index(). However, if you have thousands of products, you can’t expect the function to be able to index all of them at once; the process likely times out. So, you need a series of actions that index a part of the index until everything is done. It’s documented here.

    Thread Starter informaticaesporien

    (@ifoesporien)

    Hello Mikko, i installed the wp crontrol plugin and created a cron with the php code relevanssi_build_index( true, false, 100 ); but it doesn’t work.

    Plugin Author Mikko Saari

    (@msaari)

    What do you mean it doesn’t work? Where it fails? How are you running this?

    Thread Starter informaticaesporien

    (@ifoesporien)

    I created this cron event but it doesn’t work. https://snipboard.io/CTLc2O.jpg

    Plugin Author Mikko Saari

    (@msaari)

    This indexes 100 unindexed posts every day. That’s not going to do anything.

    You need to run relevanssi_build_index( true, true, 100 ) first to empty out the index, then run relevanssi_build_index( true, false, 100 ) again and again until all posts are indexed. The 100 is a low value; you can experiment how big a number you can use. Maybe you can use 500, for example, and can set up the cron job to run relevanssi_build_index( true, true, 500 ) in the middle of the night and then run relevanssi_build_index( true, false, 500 ) as many times as a necessary every five minutes after the initial indexing process.

    Thread Starter informaticaesporien

    (@ifoesporien)

    Yes, but I have non-indexed products and I have checked the run now option and it does not index the new products.

    Plugin Author Mikko Saari

    (@msaari)

    It doesn’t increase the number of indexed posts in the Relevanssi Indexing screen under “State of the index”?

    Thread Starter informaticaesporien

    (@ifoesporien)

    Hello Mikko, no, it doesn’t.

    Plugin Author Mikko Saari

    (@msaari)

    If you set the second parameter to true, does it wipe out the index?

    Thread Starter informaticaesporien

    (@ifoesporien)

    No, i tried it too.

    Plugin Author Mikko Saari

    (@msaari)

    Are you sure the cronjob works? Does the function run in the first place? If you log the return value of the function, what does that say (error_log( print_r( relevanssi_build_index(...), true ) ))?

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Build the index once a day’ is closed to new replies.