Description (content) character counts include non-diplayed characters

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Description (content) character counts include non-diplayed characters

This topic contains 1 reply, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 7 years, 10 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #8855

    I love your product, but I think there is a small bug in the Layout options/Results Layout/Description (content) length parameter. It is counting non-renderable characters as part of the total content character count, which doesn’t make sense.

    Example using dummy text: I am displaying my search results in an isotropic format, and the excerpt of my post has 584 characters, including spaces:

    <a title="Buy it here directly from Hermes" href="http://localhost/recommends/hemes-direct/" rel="nofollow">Buy it here directly from Hermes 2 &gt;</a>  
    <a href=";ie=UTF8&amp;qid=1461628898&amp;sr=1-4&amp;keywords=tilley+hat">Buy it from Amazon here</a>
    Hand-made.  Silk. Work-of-wearable art.  Useable in any season, the ultimate accessory. <a title="Read more" href="http://localhost/2016/05/09/best-womens-scarf/"> Read more &gt;</a>

    However, the displayed text should only have 162 characters, including spaces and special characters like “&gt” which is rendered as “>”. The excerpt should be rendered like this:
    Buy it here directly from Hermes 2 >
    Buy it from Amazon here >
    Hand-made. Silk. Work-of-wearable art. Useable in any season, the ultimate accessory. Read more >

    Yet, when I limit the character count to 200 characters, which more than covers a full rendering of the displayable text, Ajax Pro actually only displays this:
    Buy it here directly from Hermes 2 >

    because Ajax Search Pro is counting non-renderable characters in the content character length parameter. This is a problem because it is difficult to create uniformly-sized excerpts when there are links in the excerpt, or other non-renderable characters. Can this be tweaked in the Ajax Search Pro backend?

    • This topic was modified 7 years, 10 months ago by trw226 trw226.
    Ernest Marcinko
    Ernest Marcinko


    I’ve given this one quite a lot of thought, but once it comes to HTML tags and non-readable characters it’s very difficult to put together a good solution.

    – While it would be actually possible to distinguish a set of non-readable charaters from others (including persian and other languages), there is no way of measuring the length of the actualy HTML tags, which can and do contain alphanumeric characters. The calculation then would only exclude the special ones, but it’s a relatatively small portion compared to the actual HTML tags and all of their attribues (like href, style, classes etc..)

    – A different approach perhaps is to clear the text from HTML and measure it’s length, and somehow find the last words in the original with the closing HTML tags. In this case however after stripping the tags, there is no information left on their positions, meaning it’s almost impossible to find the corresponding part in the original, with the desired HTML tags.

    I’ve done some research if there is already a smart way of calculating text only, but leaving desired HTML in tact, but I could not find anything reliable I could implement or start off with.

    The best workaround I can think of in this situation is to create a custom field to be used as the description and store the desired description text there. In that case you can increase the count to a very high number to never reach the end, like 700 or so. On the Advanced Options panel then you can choose that custom field as the primary description field.

    Ernest Marcinko

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

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

You must be logged in to reply to this topic.