We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30215
    • 79 Posts
    I have set up AjaxSearch to search in my galleries and documents. Problem is that when I search for example "Linux" and there is one image in one gallery called "Linux", placeholder [+as.gal_id+] returns ALL images from this gallery, not only the one called "Linux". And as my gallery contains about 400 images, it doesn’t look nice in search results smiley

    [!AjaxSearch? &ajaxSearch=`0` &whereSearch=`content|maxigallery` &clearDefault=`1`  &parents=`2,3,4` &depth=`2` !]


    As you can see, this is quite simple AjaxSearch call. I use AjaxSearch 1.9.0 and I haven’t touched the default settings.

    To be more precise I run AjaxSearch in debug mode. The log is attached to this comment.
      -- sorry for my english, bad teacher smiley
      • 5811
      • 1,717 Posts
      Problem is that when I search for example "Linux" and there is one image in one gallery called "Linux", placeholder [+as.gal_id+] returns ALL images from this gallery, not only the one called "Linux". And as my gallery contains about 400 images, it doesn’t look nice in search results
      Yes. But I can’t do more. When you search for an image you get the document where the image is displayed. Use [!MaxiGallery? &pic_query_ids=`[+as.gal_id+]` &galleryPictureTpl=`subSearchGalleryPictureTpl`!] in your template to display the page with images.

      See this post for more informations.
        • 30215
        • 79 Posts
        I don’t understand

        http://www.modx.wangba.fr/index.php?id=104

        This is ONE document with ONE gallery containing a lot of pictures. But when I search for example "Peterhof", I got only two pictures, both containing "Peterhof" in the title. What is the trick?
          -- sorry for my english, bad teacher smiley
          • 5811
          • 1,717 Posts
          No tricks ...

          I don’t know where is the "linux" searchterm, but you got too much results:
                                      [gal_id] => 105,106,107,104,111,110,108,109,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,525,526,527,528,529,530,531,532,533,534,535,536,537,538,539,540,4266,4267,4268,4269,4270,4271,4272,4273,4274,4275,4276
                                      [gal_title] => , můj krásný notebook, David Hornát, Matěj Šalátek, za nimi zleva Filip Thieme, Tomáš Hájek, Pavel Rudolf, Matěj Šalátek - David Hornát, Opatovice, Linux
                                      [gal_descr] => 
                                      [gal_filename] => vladstudio_aflyingtree2_1920x1200.jpg, vladstudio_aflyingtree3_1920x1200.jpg, vladstudio_abovetheclouds_1920x1200.jpg, vladstudio_airlines_1920x1200.jpg, vladstudio_aflyingtree_1920x1200.jpg, vladstudio_airlines2_1920x1200.jpg, vladstudio_Adele_Bloch-Bauer_I_1920x1200.jpg, vladstudio_aftertherain2_1920x1200.jpg, vladstudio_lettereater_1920x1200.jpg, vladstudio_primitive_1920x1200.jpg, vladstudio_warli_1920x1200.jpg, vladstudio_cherepaha_1920x1200.jpg, vladstudio_seasons_1920x1200.jpg, vladstudio_spectrum_1920x1200.jpg, vladstudio_ilovesummer_1920x1200.jpg, vladstudio_blueflame_1920x1200.jpg, vladstudio_teddybear_mac_1920x1200.jpg, vladstudio_vegetarian_1920x1200.jpg, vladstudio_treeofbooks_1920x1200.jpg, vladstudio_alice6_1920x1200.jpg, vladstudio_thetwoandtheelephant_1920x1200.jpg, vladstudio_feelingshappy_1920x1200.jpg, vladstudio_googledatacenter_1920x1200.jpg, vladstudio_valentine_night_1920x1200.jpg, vladstudio_michel_1920x1200.jpg, vladstudio_right_1920x1200.jpg, vladstudio_eos8_1920x1200.jpg, vladstudio_castle_1920x1200.jpg, vladstudio_calm_1920x1200.jpg, vladstudio_tokyopan2_1920x1200.jpg, vladstudio_emotion7_1920x1200.jpg, vladstudio_malevich_1920x1200.jpg, vladstudio_serpenteau_1920x1200.jpg, vladstudio_motion_1920x1200.jpg, vladstudio_talzy2_1920x1200.jpg, vladstudio_talzy3_1920x1200.jpg, vladstudio_roadtobaikal_1920x1200.jpg, vladstudio_squares2_1920x1200.jpg, vladstudio_nightflower_1920x1200.jpg, vladstudio_aquawave_1920x1200.jpg, vladstudio_planet_paris_1920x1200.jpg, vladstudio_oldglass_1920x1200.jpg, vladstudio_solarsystem_1920x1200.jpg, vladstudio_timeflow_1920x1200.jpg, vladstudio_valentine_iloveyou_girl_1920x1200.jpg, vladstudio_umbrella_1920x1200.jpg, vladstudio_towardsthewithin_1920x1200.jpg, vladstudio_hearts3_1920x1200.jpg, vladstudio_wakeup_1920x1200.jpg, vladstudio_safari_night_1920x1200.jpg, vladstudio_octopuses_1920x1200.jpg, vladstudio_dragonology4_1920x1200.jpg, vladstudio_ystar_1920x1200.jpg, vladstudio_xmas_1920x1200.jpg, vladstudio_lonelyplanet2_1920x1200.jpg, vladstudio_microhorse_1920x1200.jpg, vladstudio_bound_1920x1200.jpg, vladstudio_underwater3_1920x1200.jpg, vladstudio_inthisworld_1920x1200.jpg, vladstudio_charango_1920x1200.jpg, vladstudio_thetwoandthenightmare_1920x1200.jpg, vladstudio_siberianwinter_1920x1200.jpg, vladstudio_clocks_1920x1200.jpg, vladstudio_microbes_1920x1200.jpg, vladstudio_selfportrait_1920x1200.jpg, vladstudio_giddyup_bickhamscript_1920x1200.jpg, vladstudio_anglerfish_1920x1200.jpg, vladstudio_meduza3_1920x1200.jpg, vladstudio_oldworld_1920x1200.jpg, vladstudio_photoshopping_1920x1200.jpg, vladstudio_elephant3_1920x1200.jpg, vladstudio_springinjapan2_1920x1200.jpg, vladstudio_duality_1920x1200.jpg, vladstudio_allisfullofbutterflies_1920x1200.jpg, vladstudio_theystolethemoon3_1920x1200.jpg, vladstudio_squareelephantwashere_1920x1200.jpg, vladstudio_glagolitic2_1920x1200.jpg, vladstudio_cathedrals_barcelona_1920x1200.jpg, vladstudio_blex_1920x1200.jpg, vladstudio_theystolethemoon_1920x1200.jpg, vladstudio_venice_grandcanal_1920x1200.jpg, vladstudio_christmaslogin_1920x1200.jpg, vladstudio_insidesnowflake_1920x1200.jpg, vladstudio_bound3_1920x1200.jpg, vladstudio_waitingforspring_1920x1200.jpg, vladstudio_je_taime_girl_1920x1200.jpg, vladstudio_halloween_1920x1200.jpg, vladstudio_motion3_1920x1200.jpg, vladstudio_pregnant_1920x1200.jpg, vladstudio_melody_1920x1200.jpg, vladstudio_underwater4_1920x1200.jpg, vladstudio_medieval_1920x1200.jpg, vladstudio_ooleetka_cold_1920x1200.jpg, vladstudio_hearts5_1920x1200.jpg, vladstudio_harmony_1920x1200.jpg, vladstudio_alice4_1920x1200.jpg, vladstudio_dayandnight_1920x1200.jpg, vladstudio_firsanov_fisherman_1920x1200.jpg, vladstudio_skitrack_1920x1200.jpg, vladstudio_palantir_1920x1200.jpg, vladstudio_bound4_1920x1200.jpg, vladstudio_skiing_1920x1200.jpg, vladstudio_fall_1920x1200.jpg, vladstudio_whitehorse_1920x1200.jpg, vladstudio_sunsettree_1920x1200.jpg, vladstudio_together_1920x1200.jpg, vladstudio_waitingforthemiracle_1920x1200.jpg, vladstudio_alienhousewife_1920x1200.jpg, vladstudio_treeswithlabyrinths_1920x1200.jpg, 
                                  )


          In the demo by searching "peterhof", I got only 2 results. Then by using [!MaxiGallery? &pic_query_ids=`[+as.gal_id+]` &galleryPictureTpl=`subSearchGalleryPictureTpl`!] I display a search result with a gallery composed of 2 images.

          So, to reduce the number of results do the search only in the maxigallery fields:
          [!AjaxSearch? &ajaxSearch=`0` &whereSearch=`content:NULL|maxigallery` &clearDefault=`1` &parents=`2,3,4` &depth=`2` !]
          by using content:NULL this will avoid to find "linux" in the field of the site_content table.



            • 30215
            • 79 Posts
            "Linux" is in the last image title.

            [gal_title] => , můj krásný notebook, David Hornát, Matěj Šalátek, za nimi zleva Filip Thieme, Tomáš Hájek, Pavel Rudolf, Matěj Šalátek - David Hornát, Opatovice, Linux


            So I have to search only in maxigallery to get rid of the useless pictures?
              -- sorry for my english, bad teacher smiley
              • 5811
              • 1,717 Posts
              So I have to search only in maxigallery to get rid of the useless pictures?
              No, I think that a regression has occured between 1.8.4 and 1.9.0.
              In the previous version, the id of the image was selected only if the title (and/or) the description contained the searchterm. Now they are all selected with the only one where the searchterm has been found undecided
              This regression comes from the fact, that I had several requests to have the content of TVs even if they don’t contain the searchterm. Unfortunately I applied the change for the tv but also for maxigallery and jot.

              I need more time to analyse and understand where is the problem and propose a correction. Thanks for your feedback.

              Registered as AJAXSEARCH-69
                • 30215
                • 79 Posts
                So good luck! smiley I hope you’ll fix it soon.
                  -- sorry for my english, bad teacher smiley
                  • 30215
                  • 79 Posts
                  Unfortunately I need this working now so I made a temporary solution. It might be useful for someone.

                  I made a phx modifier which takes all found ids of images and selects only the right of them. This isn’t exactly fast but I couldn’t find anything better.

                  Modifier gallerysearch:

                  <?php
                  global $modx;
                  $titles = $options;
                  
                  // get the searchterm
                  $searchterm = $_REQUEST["search"];
                  if (get_magic_quotes_gpc()!==1)
                      $searchterm = addslashes($searchterm);
                  
                  // create LIKE for each word
                  $terms = Array();
                  foreach (explode(" ", $searchterm) as $term) {
                      if (!preg_match("~$term~i", $options)) continue; // remove terms which are not in titles
                      $terms[]="`title` LIKE '%$term%' OR `descr` LIKE '%$term%'";
                  }
                  
                  if (count($terms) > 0) {
                      // search images
                      $db = $modx->db->query("SELECT `id` FROM ".$modx->getFullTableName('maxigallery')." WHERE `id` IN (".$output.") AND (".implode(" OR ", $terms).") ");
                  
                      // create string for maxigallery
                      $ids = Array();
                      while ($r = mysql_fetch_array($db)) 
                          $ids[]=$r['id'];
                      return implode(',', $ids);
                  }
                  else return '';
                  ?>


                  To improve the performance I made an extra phx modifier (picturesfound) which returns whether the searchterm is at least included in [+as.gal_title+] (otherwise it’s not necessary to look in the database).

                  <?php
                  $titles = $output;
                  
                  // get the searchterm
                  $searchterm = $_REQUEST["search"];
                  if (get_magic_quotes_gpc()!==1)
                      $searchterm = addslashes($searchterm);
                  
                  // if a word of searchterm is in titles, return 1 
                  foreach (explode(" ", $searchterm) as $term) 
                      if (preg_match("~$term~i", $titles)) return 1;
                  
                  // no pictures found
                  return 0;
                  ?>


                  My result.tpl looks something like that then:

                  [+as.gal_title:picturesfound:isnot=`0`:then=`
                     [[MaxiGallery? &pic_query_ids=`[+as.gal_id:gallerysearch=`[+as.gal_title+]`+]` &galleryPictureTpl=`subSearchGalleryPictureTpl`]] 
                  +]
                    -- sorry for my english, bad teacher smiley
                    • 5811
                    • 1,717 Posts

                    Thanks tobice to test the attached correction of the file classes/ajaxSearchRequest.class.inc.php.
                    Let me know the results.
                      • 30215
                      • 79 Posts
                      Hey, I didn’t know you would be so fast laugh It was nice evening spent by writing those now useless snippets.

                      It seems to be working, the results are correct and it’s faster than my solution. So thank you!
                        -- sorry for my english, bad teacher smiley