Get WPFTS Pro today with 25% discount!

How to implement FullTextSearch on a page?


  • Re: Sorry no posts match your criteria

    Hello all, I am brand new to this forum. I have imported 1700+ PDF attachments (into the WordPress Media Library), and I need to offer a way for site visitors to search those documents for specific text, terms, etc. I have installed the WPFTS Pro trial, so that I can test it before purchase.

    Using the Test Search under the plugin's Sandbox area, I was able to verify that the search is working perfectly. However, I need to implement a Search feature for web visitors (very similar to the one on [https://searchannavonreitz.americanstatenationals.org/](link url). When you enter your search term on that page, then click the Find button, you get redirected to a search results page that is a list of PDF files that the search term(s) are found in.

    I need to default the Post Type to "attachment", and the Post Status to "*(Any)", just like on the Test Search. However, I do not want to show any of these Additional Options that are shown on the Test Search to the users. It should look just like the search that was implemented in the referenced post. I need to restrict the search to attachments, because I don't want any results returned other than those from the 1700+ attached PDF files.

    I am using Elementor page builder for the site, so implementing this with a shortcode would be ideal, but I am open to any suggestion. This is a FANTASTIC plugin, and I am ready to purchase if I can get some help on how to implement it on a search page.

    Any help is appreciated.

    Larry


  • Hi, Larry

    I've already answered you to email, but have to copy the answer here just for upcoming users.

    Yes, we can make a filter that only searches for "attachment" records.
    To do this, you'll need to add a small addon plugin. It adds a Preset, which can then be selected in the list when adding "WPFTS :: Live Search" widget to the page.

    Earlier we contacted about Document Library Pro record search. These records are of a different type (dlp_document), but we can make a Preset for them too.

    Specify what you would like to use.

    Please before installing next addons, update the main WPFTS Pro package (Pro 2.49.205 or later, I given you the link in the letter)

    Here is an Addon which have two presets:

    • "Media Files Only" - this will search for Media Library files only,
    • "Document Library Pro Only" - this is for DLP documents only.

    https://fulltextsearch.org/wpfts-addon-for-larry-1.0.1.zip

    You need to download, install and activate the addon plugin. No rebuild index required on this step.

    Also here is an addon for Document Library Pro, install it, activate. Then make a fast test: open any Document Library document for Edit in WP Admin and simple Update (Save) it.

    This will trigger the index rebuild for this particular document, and in case the Document Library Addon works fine, you will be able to find this Document in the Test Search.

    https://fulltextsearch.org/wpfts-addon-document-library-pro-1.1.2.zip

    When this works, you can make a complete index rebuild to get all your Document Library Pro documents indexed.

    Let me know how it comes with tests. Thanks!


  • @epsilonadmin Yes, I saw your email, and I am following the instructions right now on a new staging site that has all 1700+ documents stored externally on the server. I sent you an email asking another question, but I will repeat here for others:

    Can you please point me to instructions on how to add the WPFTS::Live Search widget to a page?

    I want to implement something just like this:

    [https://searchannavonreitz.americanstatenationals.org/](link url)

    If you enter the word "consent" in the search field (without the quotes), then click the Find button, you will be redirected to a search results page showing all the PDF files that contain the search term.

    So, if you could please direct me to some documentation on how to implement the widget on a page, I would be grateful!

    Regards,

    Larry


  • Hi, Larry

    About the WPFTS :: Live Search widget. This widget should be in your widget library (where all other widgets are listed). You can put it on the sidebar or another widget area and fill up some Settings inside the widget form as displayed below:

    E20221005-022126-001[1].png

    Alternatively you can use shortcode to insert the widget into any text content. It can be done with:

    [wpfts_widget preset="<preset_id>" title="" placeholder="Search..." button_text="Search" hidebutton="0" class=""]
    

    You need to put preset_id value to "preset_media" if you want to search for Files Only with this widget or "preset_dlp" for Document Library Pro documents only.

    title can be set in case you want to have a widget title above the input, placeholder and button_text are the texts inside the input and button. Also you can hide the button ("enter key" to start search) by hidebutton=1 and you can set up CSS class via class attribute in case you want to customize widget style.

    Hope this is clear. Feel free to ask if you have some questions!


  • Well, when I navigate to Appearance > Widgets, I don't see the WPFTS Live Search widget (see attached image).

    However, I was able to successfully use the shortcode information you provided to add a search widget to a page. You can see it here:

    https://staging4.hamlinny.org/document-center/

    Ignore the Search field on the right ... that belongs to the Document Library Pro plugin, and will be going away soon.

    So, enter "Program Notice" in the WPFTS search field and click the Search button. You will see 25 pages of results, however, the results only show the PDF filenames. Is there any way to get search results like you see here:

    [https://searchannavonreitz.americanstatenationals.org/?s=consent&numberposts=30&results_hide_fields=](link url)

    Those search results include:

    Filename
    Date/Author
    Excerpt showing highlighted occurrences of the search term
    Score
    Download link

    How do I get my search results to include all that information?

    Also, am I forced to use the archive search results page to display the results? While the archive sidebar is required on the archive page, I would really rather NOT see it on my WPFTS search results page.
    widgets.jpg
    Thank you so much ... I am getting very close!

    Larry


  • This new Widget editor is crazy, I think there are sidebars on the left and you need to press [+] to see the list of available widgets.

    Okay, for search results style: it looks like your theme is allowed to show the post title only. I don't see here if you are using Elementor to create search results page or you are using theme's default search results page. In the first case you need to add those items (author/date/excerpt) in Elementor. In the second case you need to tell me which theme you are using so I can see if it possible to switch on those fields on the theme settings or make a fix.

    BTW you can search for the theme name over this forum to find any fixes that we already done before.


  • @EpsilonAdmin Ok, I see all the widgets when I click the [+], including your WPFTS::Live Search widget!

    I will not be using the WPFTS widget in the sidebar for now, but I will definitely remember it in the future.

    As for the theme, I am using the Astra (free) theme. The Quick Links Sidebar that you see in the image attachment to my last post is the sidebar that appears on all the pages, including the post archive page. You can see the archive page here:

    [https://staging4.hamlinny.org/news/](link url)

    I am pretty sure I am using the Astra theme's default search results page, because I don't remember specifying otherwise.

    I will search the forum for the Astra Theme to see if I can find any more info. In the meantime, if you can take a look at the Astra theme and see if there is any way to make it display the additional information on the search results page, that would be great!

    FYI, I edited one of the existing DLP documents, and the Author field at the bottom was already specified. I also added an author (the same author) on the right hand side in the DLP edit screen, and also added an Excerpt. However, after saving everything and clearing cache, and re-searching, still only the document title shows up on the search results page.

    I am attaching the edit screen for the DLP document, so you can see what I am talking about.

    I am also attaching a closeup of the Astra Settings section of the DLP edit screen, where you can select the type of sidebar, but I don't know if that is relevant to my problem or not.

    I can provide login credentials to the staging site via email, if you think it would help your investigation. Just let me know.

    I appreciate all your help!

    Larry
    document-library-pro.jpg
    astra-settings-sidebar.jpg


  • @EpsilonAdmin Ok, so after my last reply, I found this post about the Astra theme not showing Smart excerpts:

    [https://docs.fulltextsearch.org/forum/topic/92/solved-the-astra-theme-does-not-show-smart-excerpt-for-files?_=1664945965846](link url)

    So I implemented the solution mentioned in that post, and it helped a lot (but still missing SOME information). To see the current status, go to my Document Search page here:

    https://staging4.hamlinny.org/document-center/

    and enter "Program Notice" in the search field (without the quotes), and click the Search button. You will now see this search results page:

    [https://staging4.hamlinny.org/?wpfts_wdgt=preset_dlp&s=Program+Notice](link url)

    You can see that now there is an excerpt shown, along with highlighted references to the search term, and also a Score.

    However, is there any way to also get the Article Author/Date and a Download link, like that shown on the previously mentioned site? Shown here:

    https://searchannavonreitz.americanstatenationals.org/?s=consent&numberposts=30&results_hide_fields=

    I know that the document names that show up on the search results page are hyperlinked to the document, but it would still be nice to get the Download link to appear, like on the previously mentioned site, and also the document date. If that is not possible, is it at least possible to get the hyperlinked document title to open in a new tab?

    One last thing: If you enter nothing in the search field, then click the Search button, nothing should happen. Instead, it takes you to the search results page and shows many pages of document titles. Can this be fixed?

    Thank you so much!


  • Hi, Larry

    The Date and Author is not related to WPFTS, it's the theme author preferences - whether include Date and Author info to the post list. However, thanks to WP's hook system we can add this functionality with a simple code.

    I would recommend to place it into the child theme's functions.php, however you can put it into the main theme functions.php if you are not using child theme.

    add_action('astra_entry_content_before', function()
    {
    	if (is_search()) {
    		// Modify search result posts
    		// Add date and author
    		$author = get_the_author();
    		$author_url = get_the_author_link();
    		
    		echo '<span class="post-meta-infos"><time class="date-container minor-meta updated" itemprop="datePublished">'.the_date().'</time><span class="text-sep"> / </span><span class="blog-author minor-meta">by <span class="entry-author-link" itemprop="author"><span class="author"><span class="fn"><a href="'.htmlspecialchars($author_url).'" title="Posts by '.htmlspecialchars($author).'" rel="author">'.htmlspecialchars($author).'</a></span></span></span></span></span>';
    	}
    });
    

    This code will add Date and Author info to search results.


  • @EpsilonAdmin Thank you!

    On the search results page, when clicking on the titles to open a document, is there a way to make that open in a new browser tab, rather than in the same tab?

    Thanks again.


  • Hi, Larry

    Yes, we can use Astra-specific hook to add target="_blank" attribute to the title's link.

    Also I made a hook that adds "Download" link below near to "score" value. Unfortunately it's hard to detect filesize at this point (since the file can be located on another server).

    Place this code right below the code that I posted above, in the functions.php:

    
    // Hook to force search result files to open in new tab
    add_filter('astra_the_post_title_before', function($before)
    {
    	if (is_search()) {
    		// Modify the search result title
    		$before = preg_replace('/<a\s+href=/', '<a target="_blank" href=', $before);
    	}
    	
    	return $before;
    });
    
    // Hook to add "Download" link below the excerpt (near the "Score" value)
    add_filter('wpfts_se_output', function($a, $post)
    {
    	if ($a && $post) {
    		if (isset($post['post_type']) && ($post['post_type'] == 'dlp_document')) {
    			// Add Download button
    			$shift = (strlen($a['score']) > 0) ? ' wpfts-shift' : '';
    
    			$link = '';
    
    			$post_id = $post['ID'];
    			
    			$link_type = get_post_meta($post_id, '_dlp_document_link_type', true);
    			$file_size = get_post_meta($post_id, '_dlp_document_file_size', true);
    			$file_id = get_post_meta($post_id, '_dlp_attached_file_id', true);
    			$link_url = get_post_meta($post_id, '_dlp_direct_link_url', true);
    
    			$local_url = false;
    			if ($link_type === 'file') {
    				// The attachment post
    				if ($file_id > 0) {
    				
    					$link = wp_get_attachment_url($file_id);
    				}
    			
    			} elseif ($link_type === 'url') {
    				// The link
    				$link = $link_url;
    			} else {
    				// Unknown link_type
    			
    			}
    			
    			if (strlen($link) > 0) {
    				$a['link'] = '<a target="_blank" class="wpfts-download-link'.$shift.'" href="'.esc_url($link).'"><span>'.__('Download', 'fulltext-search').'</span></a>';
    			}
    		}
    	}
    	
    	return $a;
    }, 10, 2);
    

    Hope this helps. Thanks you!


  • @EpsilonAdmin This works great except for one small error in the constructed download link. For example, here is the constructed link for one of the search results:

    https://https//staging4.hamlinny.org/documents/assessors-office/assessment-rolls/2019/2019-Final-Roll.pdf

    The second occurrence of the "https//" is unnecessary.

    I tried to fix this, but php is not my strong point.

    Larry


  • Okay, Larry,

    could you please show me how the links looks like when added to the Document Library Pro document edit window in WP Admin?
    I just checked on my side and I don't see this problem, so I think the difference is how we put links to documents.

    Thanks!


  • @EpsilonAdmin Attached is a screen cap of one of the documents. The full link for this document is:

    https://staging4.hamlinny.org/documents/assessors-office/assessment-rolls/2019/2019-Final-Roll.pdf

    If you go to my documents page here:

    [https://staging4.hamlinny.org/document-center/](link url)

    and search for the word "Sewer" (without the quotes), this document will be the first one in the search results. Note that the link for the title is correct, while the URL for the Download link is incorrect.

    edit-document.jpg


  • Okay, Larry,

    please could you go to the code we added last time and replace 6th line from the end:

    $a['link'] = '<a target="_blank" class="wpfts-download-link'.$shift.'" href="'.esc_url($link).'"><span>'.__('Download', 'fulltext-search').'</span></a>';
    

    by this one:

    $a['link'] = '<a target="_blank" class="wpfts-download-link'.$shift.'" href="'.htmlspecialchars($link).'"><span>'.__('Download', 'fulltext-search').'</span></a>';
    

    (actually only esc_url has been replaced by htmlspecialchars).

    I think this function breaks the URL somehow on your server (and it's VERY strange).

    Please let me know. Thanks!


  • @EpsilonAdmin I replaced esc_url with htmlspecialchars, but that didn't fix the issue. Very strange, indeed.

    You can see when you mouseover the Download link that the url is incorrect, right? But the link on the title is correct!


  • @sanfordandson Could there be something in the .htaccess file that is causing this?


  • I don't think so, it looks like a PHP problem.

    Which version of the Document Library Pro you are using?


  • @EpsilonAdmin 1.7.2 (current version)


  • @sanfordandson I know it's a cludge, but could you strip out all occurrences of "https//"? That would make the url correct.

Suggested Topics

  • 0 Votes
    1 Posts
    372 Views
    No one has replied
  • 0 Votes
    1 Posts
    463 Views
    No one has replied
  • metadata filter in WPFTS widget

    Recipes and Known Solutions
    2
    0 Votes
    2 Posts
    568 Views
    EpsilonAdminE

    Hi @pfb6736

    Yes, you can do this via CSS, either by adding a new rule to your Theme custom CSS block, or you can use WPFTS Settings / Search & Output / Display / Smart Excerpts CSS editor block.
    I hope it's .widget.widget-search rule, you can set 'width: 100%' to extend widget's width to all available room.

    The plugin is growing, but we have not yet a powerful system to make customized search widgets. What I can propose to you is (depending on your PHP/WP knowledge): there is a file /includes/widgets/wpfts_widget.class.php which is actually a native WP search widget with some changes for Live Search functionality.
    I would recommend you to copy this file to your child theme and create your own widget (by adding a select input to existing code). In case you think your knowledge of PHP is not that good, I can gladly help you, but you need to explain to me what exactly you need.

    Yes, it's possible via the small code addition. Do you want to show a path to the file instead of the file title? Or it should be an additional line in the search result item? Do you think showing a local path to the file is OKAY and maybe it's better to show Category instead?

    As I can see they are highlighted (bolded) but you can change this again in the Smart Excerpts CSS block. For example, this rule will make found words RED and YELLOW highlighted.

    .wpfts-result-item .wpfts-smart-excerpt b { /* Excerpt text */ color: red; background-color: #ff3; }

    Thanks.

  • 0 Votes
    1 Posts
    783 Views
    No one has replied
  • 0 Votes
    4 Posts
    1k Views
    EpsilonAdminE

    In the Divi 4.9.10 the respective line number to patch is 1913.

Be the first to read the news!

We are always improving our products, adding new functions and fixes. Subscribe now to be the first to get the updates and stay informed about our sales! We are not spammy. Seriously.

Join Us Now!

We are a professional IT-team. Many of us have been working in a Web IT field for more than 10 years. Our advanced experience of software development has been employed in the creation of the WordPress FullText Search plugin. All solutions implemented into the plugin have been used for 5 or more years in over 60 different web-projects.

We are looking forward to your comments, requests and suggestions in relation to the current plugin and future updates.

ewm-logo-450

The forum powered by NodeBB | Contributors