Finetuning search results

This topic contains 8 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 1 week, 1 day ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #38018
    georg.demcisin
    georg.demcisin
    Participant

    Hello,

    I have two questions for setting up the search results. Hopefully you can help. For testing purposes you can use https://www.mitteilungen.at/elisabeth-vavra-die-mitteilungen/ where you also find a pdf.

    1) Currently I am searching in posts, pages and media. Is it possible to group the results and show what kind of content it is. So e.g. first heading “posts” below all results found in posts, second heading “pages” below all results found in posts and third heading “media/pdf” …?

    2) Is it possible to show some description similar to pages/posts also for search results within pdf? E.g. in the above mentioned pdf you can search for “Josef Faber”. The results show the title of the pdf file where this name was found however no details about which page or at least the description with the highlighted search text?

    Thanks,
    Georg

    #38033
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Georg,

    Thank you for the details, it helps a lot!

    1. Yes – for the vertical results layout there is a grouping feature. I believe the grouping by post type will help with your case.

    2. The file content text is not easy to access, that would not work. However the page excerpt (where the media is attached to), could potentially work via a custom code.

    Try adding this code to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.

    add_filter( 'asp_results', 'asp_attachment_content_field', 10, 1 );
    function asp_attachment_content_field( $results ) {
      foreach ($results as $k=>&$r) {
    	if ( $r->content_type == 'attachment' ) {
    		$parent_id = wp_get_post_parent_id( $r->id );
    		if ( !is_wp_error($parent_id) && !empty($parent_id) ) {
    			// Change the link to parent post permalink
    			$r->content = wd_substr_at_word( get_post_field('post_content', $parent_id), 130 );
    		}
    	}
      } 
      return $results;
    }

    If all goes well, and the media files are attached to a parent post/page, this should fetch the content of those and append to the result.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #38157
    georg.demcisin
    georg.demcisin
    Participant

    Hello Ernest,

    thanks for your answers!

    1) The grouping seems to work!

    2) I also added your code to functions.php, unfortunately it does not seem to have any effect. You can check the results again on the search page. However I also do not think this solution is suitable for us. We do not need any info from the page or post but directly from the pdf. Is there any chance to get some additional info out of the pdf? For example the page number on which the search term was found? Or e.g. 50 characters before and after the search term? It is just about making it easier for the user to find the search term when opening the pdf file.

    Thanks!
    Georg

    #38181
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    2) Well, if you happen to use the Media service addon to fetch the contents out of the PDF documents, then there might be some hope left. When using that parser, the extracted PDF text is kept in a local post meta field.
    The field name is “_asp_attachment_text”. Try this configuration: https://i.imgur.com/ca5BoA6.png
    It could actually work – although please note, that the parsed text is often times filled with various tabs, whitespaces or other characters, so it may not look correct every time.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #38208
    georg.demcisin
    georg.demcisin
    Participant

    Hello Ernest,

    thanks alot! I am really impressed by the functionality of your plugin! Last probably small issue. Is it possible to add a target=”_blank” to all PDF search result links or maybe even to all search results?

    Thanks!
    Georg

    #38209
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Georg,

    Thank you for your kind words!

    It is possible to it with all of the results: https://i.imgur.com/BxzqQwV.png

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #38620
    georg.demcisin
    georg.demcisin
    Participant

    Hello Ernest,

    one issue just showed up. Is it possible to display the search results above the search box? Unfortunately I could not find any setting for this.

    Thanks!
    Georg

    #38621
    georg.demcisin
    georg.demcisin
    Participant

    And following up on the target=”_blank” question. Is it possible to only open media files in a new window? Posts and pages should open in the same window.

    Thanks!
    Georg

    #38637
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Georg,

    You can use the results shortcode for that. Place that anywhere on the same page, the results are going to be displayed there. The floating results list can not be displayed over the search bar.

    Here it is possible to change the target window of the results. Unfortuantely that is global. To change that on attachments only, you may need a custom code instead of that option.

    add_action('wp_footer', 'asp_api__code', 99999);
    function asp_api__code() {
    	?>
    	<script>
    	(function($){
    		$(".asp_m").on("asp_results_show", function(){
    			$('.asp_r .asp_r_attachment').find('a').prop('target', '_blank');
    		});
    	})(WPD.dom);
    	</script>
    	<?php
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.