Excerpt of results not show

  • wpsolr
    Keymaster
    7 months, 3 weeks ago #35617

    You can use a hook to modify the results, including title and content: WPSOLR_Events::WPSOLR_ACTION_BEFORE_RENDER_TEMPLATE

    use wpsolr\core\classes\WPSOLR_Events;
    add_filter( WPSOLR_Events::WPSOLR_ACTION_BEFORE_RENDER_TEMPLATE, 'wpsolr_action_before_render_template', 10, 1 );
    
    /**
    * @param array $template_params
    *
    * @return array
    */
    public function wpsolr_action_before_render_template( $template_params ) {
      foreach ( $template_params['template_data']['results']['items'] as &$result ) {
        // Modify $result if title or content are empty
        if ('...' === $result['content']) {
          // Replace with original post excerpt from get_post($result['PID'])
        }
      }
      return $template_params;
    }

    You can find a full example in /plugins/wpsolr-pro/wpsolr-pro/wpsolr/pro/extensions/woocommerce/class-wpsolr-plugin-woocommerce.php

    matteo.cattelan
    Participant
    7 months, 3 weeks ago #35618

    ok I think I understand, thank you very much, is there a hook also for the “did you mean” in the case of poorly written search text?

    wpsolr
    Keymaster
    7 months, 3 weeks ago #35621

    The “did you mean” section is added just before the search results. Just tested with OpenSearch.

    matteo.cattelan
    Participant
    7 months, 3 weeks ago #35624

    If i active the option in Wpsolr backend in wordpress i have this error:

    {“error”:{“root_cause”:[{“type”:”illegal_argument_exception”,”reason”:”no mapping found for field [spell]”}],”type”:”search_phase_execution_exception”,”reason”:”all shards failed”,”phase”:”query”,”grouped”:true,”failed_shards”:[{“shard”:0,”index”:”wp_it”,”node”:”GbLND5ZMSrqT3nD1giH9Ew”,”reason”:{“type”:”illegal_argument_exception”,”reason”:”no mapping found for field [spell]”}}],”caused_by”:{“type”:”illegal_argument_exception”,”reason”:”no mapping found for field [spell]”,”caused_by”:{“type”:”illegal_argument_exception”,”reason”:”no mapping found for field [spell]”}}},”status”:400}

    Do I need to configure something?
    Thanks a lot

    wpsolr
    Keymaster
    7 months, 3 weeks ago #35626

    Let’s continue on https://www.wpsolr.com/forums/topic/didi-you-mean-error/ for the “did you mean” issue.

    matteo.cattelan
    Participant
    7 months, 3 weeks ago #35628

    ok, this issue is closed for me, thanks a lot for all.

    wpsolr
    Keymaster
    7 months, 3 weeks ago #35648

    I just realized that if you check the option “Index post excerpt” on WPSOLR’s screen “2.2 Data” (do not forget to reindex), you should see excerpts in your results when keyword highlighting is empty.

    matteo.cattelan
    Participant
    7 months, 3 weeks ago #35650

    thank you very much for the clarification, too kind but I have already solved it with the hook solution.

    Thanks

    wpsolr
    Keymaster
    7 months, 3 weeks ago #35651

    You’ll get even more control with the hook.

    By the way, did you consider using our neural search with Weaviate? Looks natural considering the AI nature of your site content!
    Some Open source Sentence Transformers models are multilingual, and vector search can scale to billions of vectors easily and cheaply.
    (their real cost is for indexing/vectorizing data where GPUs are required on large scale).

    • This reply was modified 7 months, 3 weeks ago by wpsolr.
Viewing 9 posts - 16 through 24 (of 24 total)

You must be logged in to reply to this topic.