We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4749
    • 623 Posts
    I’ve read through the threads and been to the demo site, but have never been able to make it work. For example:

    I’ve got a tv called "widget_name" and "widget_name" has different values for each widget page. Let’s say I have 200 widgets. Customers know they all have 3-4 letter names. I want for the customer to be able to type - "cro" and have the search results display only that one document that has the [*widget_name*] of "cro" attached to it. Does this make sense? Meaning I want AS to only search the [*widget_name*] tv and return results for just that widget. So, if they enter the wrong name it won’t return anything. That’s what I’m looking to do.
      The MODx has you...
      Utah Web Design
      • 5811
      • 1,717 Posts
      Hi Cbaone,

      Coming back after a long and pleasant break (vacation), I will tried to answer to your request.

      As i understand you would like display the documents which have, as tag, a tv named "widget_name" which contains the value "cro".
      Is it correct ?

      If yes, with the default &whereSearch parameter, the search occurs in "site_content" and "tmplvar_contentvalues" MODx tables.
      So the fields where we can do a search are :
      - all the searchable "string" fields of the "site_content" table (which is the main table)
      - all the concatened fields of the "tmplvar_contentvalues" table (which is here a joined table)

      This means that if you search "cro" you will get all the documents which has a the tv "widget_name" which contains the value "cro".
      if you use the default tplResult template you will display one or several extracts per document found.

      An extract is a bit of text where search term have been found (and may be highlighted).
      extract is different of whereSearch. extract define which fields will be use to set up
      the text where to extract the search term. whereSearch define which tables use for the
      search (and then provides a list of fields where to search and possibly used by extract)

      For "content", the searcheable fields available are:
      pagetitle, longtitle, description, alias, introtext, menutitle, content

      For "tv", the fields available are :
      tv_content which a concatenation of all the tv "values" field

      By default all the searchable fields of all tables are displayed, but you could redefine the extract with the &extract parameter:

      e.g: &extract=`5:description,introtext,content,tv_content`
      allows a maximum of 5 extracts per document found by search.
      Extracts display content from description,introtext,content of document AND
      tv_content from all the TV linked with the document

      Which information from the document or from a TV would you like display ?
        • 4749
        • 623 Posts
        Yes, you’re right...I think.

        How do I write out that call then?

        [!AjaxSearch? &whereSearch=`tv_content` &tplAjaxResult=`tvSearch` &extract=`1:tv_content`!]

        where do I define which tv to search?

        So, if I have 200 documents that all have a unique [*widget_name*] (cro,pop,dre,ret,its,etc.) how do I tell AS to search only those 200 documents and look in the [*widget_name*] only and return the match?
          The MODx has you...
          Utah Web Design
          • 5811
          • 1,717 Posts
          [!AjaxSearch? &whereSearch=`tv_content` &tplAjaxResult=`tvSearch` &extract=`1:tv_content`!]
          Keep the default &whereSearch parameter. So don’t define a new one. The default value is "content,tv". This value define "content" as the main table and "tv" as a joined table. As a main table is mandatory, keep "content,tv"

          In a first step don’t define a new template. Keep the default &tplAjaxResult.

          To restrict the extract value to the TV value, use &extract=`tv_content`

          So simply try first:
          [!AjaxSearch? &extract=`1:tv_content`!]
          This snippet call will display the documents which contains your searchterm ("cro") into one of the following fields:

          pagetitle, longtitle, description, alias, introtext, menutitle, content
          tv_content which a concatenation of all the tv "values" field

          Try it and let me know the results. If too much results are displayed (due to the fact that some fields of the document contains "cro" too), we will apply filters to restrict the search or the display of useless documents
            • 4749
            • 623 Posts
            OK, I added the snippet like you asked. I get too many results. I’d really like to only search one tv and display the results from the one tv.
              The MODx has you...
              Utah Web Design
              • 5811
              • 1,717 Posts
              From which fields come the results ? From Content fields like:
              pagetitle, longtitle, description, alias, introtext, menutitle, content
              or from the concatened tv values (tv_content) ? Or both ?
                • 4749
                • 623 Posts
                OK. Here it is... I have a template called "Widgets" and all of the widgets use this template. Also, I created a TV called [*widget_name*] and assigned it to the "Widgets" template. Each widget has a unique 3-4 letter identifier (for example - "cro"). I want AS to search the [*widget_name*] tv and match the search term and then display the appropriate widget. That’s it! I don’t need the content, longtitle, pagetitle - none of that. Just the TV value. Let me know if that’s not clear. Thanks for all your help.
                  The MODx has you...
                  Utah Web Design
                  • 5811
                  • 1,717 Posts
                  I understand your request but the main problem is that the search in the document occurs not only in the TVs linked to the document but also in the main fields of the document (pagetitle, longtitle, description, alias, introtext, menutitle, content).

                  And you coudn’t use the searchterm "cro" to limit with &filter, the search to the documents with a concatened value tv_content containing "cro"

                  And I haven’t imagined a parameter to restrict the fields where to do the search. So no so easy to solve without an evolution or a hack in the code.
                    • 5811
                    • 1,717 Posts
                    @Cbaone

                    An another solution could be to filter all the documents which don’t include the searchterm (e.g "cro") in the field "tv_content" (concatenation of all tv value of the document)
                    So a snippet call with &filter=`tv_content,cro,7` for instance will exlude all the documents with a field tv_content which don’t contain "cro"
                    With that we are sure that a search result has also a TV which contain your snippet value.

                    But unfortunately, the filter parameter requires a text as criterion. And in your case, the text is variable and equal to the searchterm provided by the end user.
                    So to work, it could be better to have the possibility to have something like &filter=`tv_content,#,7` where # means "searchterm provided by the end user".
                    And on fly substitute the text criterion "#" by the correct searchterm value.

                    This solution means an update of the code. Find below this update (tested locally on my own demo site). Simply substitue the file class/search.class.inc by the attached file.
                    Try it with the following snippet call:
                    [!AjaxSearch? &tplAjaxResult=`@FILE:assets/snippets/ajaxSearch/templates/tvphxAjaxResult.tpl.html` &tvPhx=`tv:displayTV` &filter=`tv_content,#,7`!]
                    The template tvphxAjaxResult.tpl.html is also attached below. I have used the name "widget_name" for your tv name. Load this file under ajaxSearch/templates/

                    I will integrate this update in the next release 1.8.1 which will coming soon to take into account some remarks and bug fixing.

                    Let me know the results.
                      • 4749
                      • 623 Posts
                      Coroico,
                      Wow! That’s service! I’ll give that a go and let you know what I find out. Thanks a million.
                        The MODx has you...
                        Utah Web Design