We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23018
    • 353 Posts
    Edit: The problem has already been solved. Reply #4 has the answer.

    I use advSearch with two selectboxes (land,species). The search goes very well and is very fast but I have a problem that gives me the shivers.

    I want to filter by a tv "db_radio_land"

    I can choose Alle (value=all) and get 142 results
    I can choose Deutschland (value=5) and get 60 results.
    I can choose Spanien (value=229) from the list and get 1 Result

    but I never get a single result for Kanaren (value=6).

    There should be 80+ results, but instead I get:

    "There were no search results. Please try using more general terms to get more results."

    How can 2 out if 3 filter conditons work and 1 not?

    Here is a link to my testpage:

    http://c0274.paas1.ams.modxcloud.com/hundedatenbank/advanced-search.html?id=205&asId=as0&land=all&gattung=all&sub=Search

    modxcloud project
    MODX v2.2.8 latest
    advSearch (1.6.1)
    Zend Lucene Search v1.12.3

    If you have a look at the results for "Alle" you can clearly see there are results for "Kanaren".

    I have checked database values, collations, charsets and other possible reasons, but to no avail.

    AS there are no problems to filter by all other properties I don't believe this can be related to the snippet calls or the hook.

    Any other ideas?

    Regard,

    pepebe [ed. note: pepebe last edited this post 10 years, 8 months ago.]
      Homepage: pepebe.de | MODX snippets (and other stuff) at github: https://gist.github.com/pepebe
      • 23018
      • 353 Posts
      To make sure that the values for land are properly set, I created a getResouces call with a tvFilter:

      &tvFilters=`db_radio_land==6`


      It shows exactly the right number of results: 82.

      Test: http://c0274.paas1.ams.modxcloud.com/testseiten/getresources2.html

      Regards,

      pepebe [ed. note: pepebe last edited this post 10 years, 8 months ago.]
        Homepage: pepebe.de | MODX snippets (and other stuff) at github: https://gist.github.com/pepebe
        • 23018
        • 353 Posts
        I know now whats going on. I'll analyze a bit more and then post about the reasons.

        Regards,

        pepebe
          Homepage: pepebe.de | MODX snippets (and other stuff) at github: https://gist.github.com/pepebe
          • 23018
          • 353 Posts
          Ok, here is the gist of the mysterious missing results.

          You can't use a TV value in a query if this value is the default value of that TV. That is because if you set a TV to its default value that value is not stored in the database. As advSearch is looking for that value in the table where tv values are stored (modx_site_tmplvar_contentvalues), it can't find them.

          Example:

          Create a Select TV "countries" (lets say the Tv gets tvId=1):
          --------------------------
          Values: Germany==1||France==2||Spain==3
          Default: 1

          Attach it to a template ("Holyday Reports") and created a new child resource of home. Title the new resource "My holidays in Germany" (resourceId=2).

          Open the resource an have a look at the value of the template. It should be "Germany". Save the resource and reload the page. TV Value is still "Germany".

          Create another child resource, "My holydays in France", and set the TV value to "France" (resourceId=3).

          Use getResources to print resource values into a webpage. Use the &tvFilter parameter to output only resources that have "Germany" as content of the countries TV

          ```
          [[!getResources?
          &parents=`1`
          &tpl=`@INLINE <li>[[+pagetitle]] Id:[[+id]] - Land: [[+countries]]</li>`
          &includeTVs=`1`
          &processTVs=`1`
          &tvPrefix=``
          &tvFilters=`countries==1`
          ]]
          ```

          If you did everything right, you'll see only one result. Remove the &tvFilters parameter and you'll see two results.

          With tvFilters and some custom snippet to create a valid filter string from POST or GET parameters you could create a fairly useful search page. Unfortunatly it would be VERY slow.

          AdvSearch to the rescue?

          Create a search form tpl with the necessary select options and add the necessary snippets AdvSearchForm and AdvSearch to your template.

          Search for "All", and you'll get 2 results.
          Search for "France" and youl'll get 1 result.
          Search for Germany and you'll get 0 results?

          The good thing is that advSearch is a hellofalotfaster, the bad thing is that 0 results are clearly not what we would expect.

          Bear with me, here comes the funny part!

          Fire up phpMyAdmin.

          Open the modx_site_tmplvar_contentvalues and have a look at the content.

          The table has only a couple of rows:

          ´´´
          id: The table index
          tmplvarid: The id of the Templatevariable, for example 1 (Countries)
          contentid: The id of the resource (
          value: Content of the TV
          ´´´

          You'll see a row with a value for contentid=3 with value=2, but no row for contentid=2.

          So the tv was stored for "France" but not for Germany.

          Go back to MODx manager change the TV Value for the resource my Holydays in Germany to "Spain". Safe your resource.

          Update the view of modx_site_tmplvar_contentvalues in phpMyAdmin and you have 2 results. The new one for contentid=2 and value=3.

          Again go back to MODX manager and change the value back to Germany.

          Update your view in phpMyAdmin once again and the second row is gone.

          Punchline:

          Prove me wrong, but I believe default TV values are never stored in the data base. The reason might be that you can change a default value whenever you want and the change will effect all resources where no other value was set. This makes sense.

          getResource knows about this fact and simply looks up the missing values. This makes it probably so slow in comparison to advSearch.

          advSearch doesn't look up the missing rows for resources that are not explicitly listed in modx_site_tmplvar_contentvalues. Therefore, you get 0 results if you are filtering a TV with a default value.

          I think there should be a parameter to force advSearch to look up those TV values. I don't know how much execution time this will cost, but at least there should be an option.

          Until then make sure that you don't query default TV values, bacause they are invisible for advSearch.

          As I never thought about the nature of default tv values, it took me quite a lot of time to find out whats going on. Lesson learned!

          Regards,

          pepebe [ed. note: pepebe last edited this post 10 years, 8 months ago.]
            Homepage: pepebe.de | MODX snippets (and other stuff) at github: https://gist.github.com/pepebe