We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42802
    • 96 Posts
    Sebastian Zahn | ingroove.uy Reply #1, 9 years, 8 months ago
    I´m working on a Real Estate website, and i need to implement a property search, and need to filter by category, price, model, m2, etc ( all of them are TVs.)

    I found simple search, but it´s very basic and don´t look in tv´s.

    Working in Modx 2.3.1

    Any suggestions?

    Thanks!

    Sebastián.

    This question has been answered by lkfranklin. See the first response.

      • 3749
      • 24,544 Posts
      getResources will filter by TVs, but it will be slow and inefficient. This article explains why: http://bobsguides.com/blog.html/2014/06/02/why-extend-modresource/.

      If you will have a lot of properties, you might consider using ClassExtender, which would extend modResource to give you those extra fields and would allow *way* faster and more efficient searches, though it would probably take some effort to set up.

      http://bobsguides.com/classextender-class.html
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
      • SimpleSearch does search TVs. See includeTVs and processTVs in the Available Properties table.
        http://rtfm.modx.com/extras/revo/simplesearch/simplesearch.simplesearch#SimpleSearch.SimpleSearch-AvailableProperties

        That said, Bob is right, searching and filtering using TVs is very slow.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 42802
          • 96 Posts
          Sebastian Zahn | ingroove.uy Reply #4, 9 years, 8 months ago
          First of all, thanks Bob and Susan for your support, you made Modx even better.

          The ClassExtender solution is too complex for my knowledge, read the Bob´s article and understood why it´s so slow to search each tv´s for results, i worked with related tables and sql join.

          Simple Search search tv´s but don´t give me the flexibility i need , for example show properties between given prices, at a specific location, etc.

          Maybe a solution could be using jquery? Load the property list in a hidden container, putting the information in data-attributes, filter and show the matching results...
            • 3749
            • 24,544 Posts
            It's really difficult to create an extra that's simple to use but still allows complex searches on what is essentially custom data.

            The main problem is that you have to find a way to create the search code from the $_POST data of a search form.

            I tried to make ClassExtender as easy to use as I could, and it's pretty simple to add the extra fields to the schema and extra fields chunks. It's also relatively easy to get the GetExtResources snippet to do very complex searches using the &where property.

            Unfortunately, the only way to use it to do what you want would be to have a custom snippet that gets the user input of the submitted form from the $_POST array, creates the appropriate &where clause, selects (or creates) the appropriate Tpl chunk, and calls $modx->runSnippet('GetExtResources') for the results. I can't think of any easier way to do it.

            It's not rocket science, but it's daunting for people who are not fluent in PHP.


              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 42802
              • 96 Posts
              Sebastian Zahn | ingroove.uy Reply #6, 9 years, 8 months ago
              I finally have the new fields working, and saves data to db and can show it, great! It was not so hard, and it´s very well explained.

              Two things, can i use this extra fields only in a specific template ( this case, properties ) so don´t show this fields on another places where won´t be used?

              To make the search, I'm thinking of doing the following: Create the html form with the data needed, pass the data via url Get to que results page, the results page is a getResources call filtering the classExtender fields with the corresponding url variable ( using fastField to get this value ). What do you think?

              Huge thanks Bob.


              Quote from: BobRay at Aug 20, 2014, 04:24 AM
              It's really difficult to create an extra that's simple to use but still allows complex searches on what is essentially custom data.

              The main problem is that you have to find a way to create the search code from the $_POST data of a search form.

              I tried to make ClassExtender as easy to use as I could, and it's pretty simple to add the extra fields to the schema and extra fields chunks. It's also relatively easy to get the GetExtResources snippet to do very complex searches using the &where property.

              Unfortunately, the only way to use it to do what you want would be to have a custom snippet that gets the user input of the submitted form from the $_POST array, creates the appropriate &where clause, selects (or creates) the appropriate Tpl chunk, and calls $modx->runSnippet('GetExtResources') for the results. I can't think of any easier way to do it.

              It's not rocket science, but it's daunting for people who are not fluent in PHP.


                • 3749
                • 24,544 Posts
                ClassExtender doesn't know anything about templates, but it's very easy to modify the plugin to handle them. If you only want to show it on pages using Template 12 (the ID is in parentheses next to the Template name in the Elements tree), just put this at the top of the plugin:

                /* Get the template ID for the current resource */
                $templateId = $resource->get('template');
                
                /* do nothing if it's not 12 */
                if ($templateId) != 12) {
                    return '';
                }


                Then the plugin will only execute for the pages that use that Template. It's a good idea because otherwise, blank values will be saved for all the other resources. That's harmless, but it's a waste of time and DB space.

                For your display, I would try using GetExtResources() first. The getResources snippet won't know about the extra fields, so you won't be able to use them in the search or the result.
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 42802
                  • 96 Posts
                  Sebastian Zahn | ingroove.uy Reply #8, 9 years, 8 months ago
                  Great! yes, i think in form customization to hide this new fields, but i suppouse that maybe it won´t know about extra fields, and like you say, a waste of db space. And for the final client, it´s good to show only what is useful.

                  Thank you Bob!

                  Quote from: BobRay at Aug 22, 2014, 07:13 PM
                  ClassExtender doesn't know anything about templates, but it's very easy to modify the plugin to handle them. If you only want to show it on pages using Template 12 (the ID is in parentheses next to the Template name in the Elements tree), just put this at the top of the plugin:

                  /* Get the template ID for the current resource */
                  $templateId = $resource->get('template');
                  
                  /* do nothing if it's not 12 */
                  if ($templateId) != 12) {
                      return '';
                  }


                  Then the plugin will only execute for the pages that use that Template. It's a good idea because otherwise, blank values will be saved for all the other resources. That's harmless, but it's a waste of time and DB space.

                  For your display, I would try using GetExtResources() first. The getResources snippet won't know about the extra fields, so you won't be able to use them in the search or the result.
                    • 3749
                    • 24,544 Posts
                    Don't thank me until it works. wink
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting
                      • 54139
                      • 3 Posts
                      Hello
                      I'm working on SimpleSearch.
                      I want to make a multi search engine using checkboxes as the selected box.
                      I want to connect these buttons with TV !!!
                      But I do not know how we do it!
                      Help will be welcome