Problems, need help? Have a tip or advice? Post it here.
14 posts Page 1 of 2
Hi, I have a little problem.

The search engine in Couch crawls the content entered in the DB. BUT I have some product pages that have a general description if they don't receive a particular one. Like:

<cms:if my_desc>
<h2><cms:show k_page_title /></h2>
<cms:show my_desc />
<cms:else/>
<p>bla bla bla General description relevant for any products #notimetoenterityetbutitisinmyproject</p>
</cms:if>

How do I get the content to be relevant for the search crawler if it is not in the DB?
I mean to apply it by default to any template that has not content yet.

It doesn't seem possible, but you never ask, you never know.

Otherwise, I end up with a result like in the screenshot attached. (m2sEkXKxQs8 is a YT video code)

Thanks

Attachments

How about putting this phrase in some 'globals' template, so it can be editable/searchable?
Couch search indexes only db stuff, although another idea is to handle search and alter the results with some code if string matches your 'special' one.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Thanks Trendoman,

It doesn't work because I need to enter things like that:

<p><span style="text-decoration:underline">Nos reproductions de tableaux sur toile de <cms:php> $print = "<cms:show k_page_title/>"; $printArray = explode(",", $print);$print = $printArray[0]; echo $print ; </cms:php> sont de très bonne facture</span>, et nous utilisons une méthode traditionnelle de reproduction qui a fait ses preuves.</p>
Everything can be solved, :) I just don't realize what you want at this moment.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Sorry if I wasn't clear.

I am selling painting reproductions online at http://www.tableaux-sur-toile.com
Each painting will eventually receive a detailed product description like that one:
http://www.tableaux-sur-toile.com/repro ... hawks.html

But if they are not, I am appending a general (let's call it temporary) description like that one (at the bottom):
http://www.tableaux-sur-toile.com/repro ... led-1.html

This temporary product description, to kept it appealing, change from product to product.
I am using, to do so, each product page k_page_title as follow:
<h2>Buy a reproduction of <cms:show k_page_title/> from our studio</h2> (for example)

To separate the artist name from the painting title I am using PHP like that:
<cms:php> $print = "<cms:show k_page_title/>"; $printArray = explode(",", $print);$print = $printArray[0]; echo $print ; </cms:php>

(I know I could have separate them from the beginning, but I didn't)

Everything works fine, except when I do a research, the temporary description does not show up in the content:
http://www.tableaux-sur-toile.com/search/?s=Minnie&nc=1

So my question is:
is there a way to include a general content description that shows in the search result without entering them one by one - which would defeat the purpose!

I would appreciate any idea that you might have, as I said, my Couch is a little rusty.

Thanks a lot,
Paolo
@KK

No idea?

I don't think it's even possible, but since you work miracles sometime...
Paolo, the problem is that Couch's search is necessarily constrained to just the database.
Since the 'temporary' descriptions do not land up into the database, they remain off-limits to the search.

As a solution, we can force those descriptions into the database.

One way of doing that could be as follows -
upon hitting save, a routine examines if the editable region designated to hold the description has been left empty.
If that is the case, the routine then dynamically cobbles up a temporary description (perhaps using a template and replacing its placeholder variables with real values like product's title etc.). This description takes the place of the empty editable region, i.e. gets saved into the database.

As you can see, now that the description is in the database the search problem is solved.

A requirement for the solution above would be to have a fixed (or predictable) pattern to use for generating the temporary description. I hope that is indeed the case.

If that is so, we'll now only need to create the 'routine' mentioned above. Couch has several 'hooks' to tap into during the save process to help with that.

Please let me know if you think this could be a valid solution.
Hi KK,
I am not sure I follow, but I'll hazard a : "YES"?
OK :)

So let us test the following out and see if that is what you want Paolo.

As you know, in v2.0 the edit-form shown in admin-panel is just a regular DBF (databound form).
For our proposed solution we'll override this default DBF with our own that will do some pre-processing of the submitted data before saving (to be specific - will check if the editable region we are interested in is empty and if yes insert a custom value instead).

There are two ways of overriding the default DBF -
1. The older way is to use custom admin-screen (covered in viewtopic.php?f=5&t=10241#p24680)
2. The recent (and more advanced) way is to override the template internally used by Couch to render the edit screen in admin-panel. You can find a complete example here - https://www.couchcms.com/forum/viewtopi ... 693#p25693

Whichever of the two you go for (I'll suggest the second method), our custom form will differ only very slightly from the default form used by Couch (which is in 'couch/theme/_system/content_form.html' template). Therefore we can simply copy that template and make the following amendments.

The portion of the code we are interested in is this -
Code: Select all
<cms:if k_success >

    <cms:db_persist_form
        _invalidate_cache='1'
        _token=k_cur_token
    />

    ..
    ..

Please modify it to make it as follows -
Code: Select all
<cms:if k_success >

    <cms:if "<cms:not_empty frm_my_desc />" >
        <cms:set tmp_value=frm_my_desc />
    <cms:else />   
        <cms:capture into='tmp_value'>
            Hello!! I am auto-generated text!
        </cms:capture>
    </cms:if>

    <cms:db_persist_form
        _invalidate_cache='1'
        _token=k_cur_token
       
        my_desc=tmp_value
    />

To explain the code -
I am assuming your editable region is named 'my_desc'. So upon successful form submission the DBF will make available the value submitted through that region as a variable named 'frm_my_desc' (i.e. append the name with a 'frm_' - regular form stuff in Couch).

Our code kicks in when the form is successfully submitted and then it checks the 'frm_my_desc' variable and stores it into a new variable named 'tmp_value'. If this value is empty, our code dynamically generates a new value and stores that instead into 'tmp_value'. Point is, the 'tmp_value' variable either contains the value explicitly submitted by our editable region or contains a dynamically generated value if nothing was submitted.

The final piece is the "my_desc=tmp_value" statement added to <cms:db_persist_form /> where we use the value contained in 'tmp_value' to save into the database as the value of 'my_desc' editable region.

And that is it.
If you think this works for you, you can place whatever code you wish into the auto-generated tmp_value. For example, instead of what I used above -
Code: Select all
<cms:capture into='tmp_value'>
    Hello!! I am auto-generated text!
</cms:capture>

- you can use the following -
Code: Select all
<cms:capture into='tmp_value'>
    <p><span style="text-decoration:underline">Nos reproductions de tableaux sur toile de
    <cms:php> $print = "<cms:show frm_k_page_title />"; $printArray = explode(",", $print);$print = $printArray[0]; echo $print ; </cms:php>
    sont de très bonne facture</span>,
    et nous utilisons une méthode traditionnelle de reproduction qui a fait ses preuves.</p>
</cms:capture>

Please note that instead of >cms:show k_page_title />, I have used <cms:show frm_k_page_title /> (i.e. prefixed a 'frm_') because the DBF will make available submitted values in that form.

In case you are not sure what values are available for you to use in the form, place the following in the <cms:if k_success >condition and submit the form. It will show all the variables (including those submitted by the form) available for use -
Code: Select all
    <cms:abort>
        <cms:dump_all />
    </cms:abort>

Hope it helps. Do let me know.
HI KK,

My page doesn't contain a form.

It's a basic product page, with a content description.

If there's no content, a general content is delivered in place of the product description.
14 posts Page 1 of 2