We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 53460
    • 69 Posts
    On our attorney pages we have a section for “related services & industries” and a list of the areas each person practices. For example: http://www.bipc.com/christopher-thorn. The field that lists all their practice areas in the CMS is set up to target the first instance and set that as their “primary” practice. This is what is used on their “cards” in the search results.

    Basically here’s an example of the problem: Using Chris Thorn’s bio above, you can see his primary practice is Immigration but he is also a member of the Labor & Employment practice. If you search for Labor & Employment (ignore the dynamic search…just hit enter), you’ll see everyone that is primarily in the Labor & Employment section is displayed. But people like Chris don’t because that phrase is not in his bio.

    Using that and looking at the sphinx.config file, it looks like only a few things are indexed in each record; the primary service (mainservice), the name, the template, the location and the content (biography) area. I’m unsure how to modify the mainservice to index ALL the variables in that section not just the first.

    My experience with MySQL is very limited, so I only have a basic understanding of what this even says. I apologize if my explanations don’t make sense at first.

    Here is the sql_query. I’ve broken it apart to read it better:

    sql_query	= SELECT 
          attorney.id AS id, 
          attorney.pagetitle AS pagetitle,
          attorney.content AS content,
          attorney.template AS template,
          location_ids.value as locations, 
          tlastnamevalue.value AS lastname, 
    
          SUBSTRING(mainservice.value, 1,36) service_id, 
           (SELECT pagetitle FROM modx_site_content WHERE link_attributes = service_id LIMIT 1) main_service, 
    
           (SELECT GROUP_CONCAT( pagetitle ) 
                FROM modx_site_content location_table 
                WHERE template =22 
                AND LOCATE( link_attributes, locations ) 
           ) location_names  
    
          FROM modx_site_content attorney   
                LEFT JOIN modx_site_tmplvar_contentvalues tlastnamevalue 
                      ON tlastnamevalue.contentid = attorney.id 
                      AND tlastnamevalue.tmplvarid = 69  
    
                LEFT JOIN modx_site_tmplvar_contentvalues location_ids 
                      ON location_ids.contentid = attorney.id 
                      AND location_ids.tmplvarid = 82  
    
                LEFT JOIN modx_site_tmplvar_contentvalues mainservice 
                      ON mainservice.contentid = attorney.id 
                      AND mainservice.tmplvarid = 81 
    
                WHERE attorney.deleted = 0 AND attorney.published=1 
                      AND attorney.template IN (16,49) 
                      ORDER BY lastname ASC
    


    I may be wrong, but the way I read this was that this SUBSTRING was selecting all the values from “mainservice” starting from the first record, the first 36 characters of each record and putting those results into “service_id”, and then only indexing that first result (LIMIT 1).

    Also, further down is a LEFT JOIN command that is defining mainservice as the items from the Template Variable #81, which is the id for Attorney Related Services.

    Then this is dumped into a string:
    sql_field_string  =  main_service


    I thought that removing the LIMIT would index all related services, but it’s still only indexing the first. How should I append this query to include all the others as well? Or at lease what should I be looking for?

    Thank you in advance.
      • 46886
      • 1,154 Posts
      I won't be able to help you with MySQL, someone else will jump in. I do think mainservice is just the one selected service, in that you said:

      The field that lists all their practice areas in the CMS is set up to target the first instance and set that as their “primary” practice.

      That primary value is, I suspect at least, mainservice.

      I would though point out that, you have the field that lists all their practice areas already, why not use that field for this purpose? It does have precisely the data you want.
        • 53460
        • 69 Posts
        Here's what I found out. I did a search for "immigration" as a pagetitle in the "modx_site_content" table and found the column from the above code called "link_attributes". The value from that was a 36 character string (044e5ccf-0f61-4a7e-9217-69c6e0828c83) that I'll just call "044e5" for short.

        Using Chris' bio above as the example, I searched for:
        SELECT value FROM modx_site_tmplvar_contentvalues WHERE tmplvarid = 81 AND contentid = 585


        The value from that column (whereas, 81 = AttorneyServices and 585 = Chris' contentid) was: 044e5ccf-0f61-4a7e-9217-69c6e0828c83||e947fe8c-3ae... The first instance of that value was "044e5", the main_service value.

        Since there are other values in each attorney bio are included as one lengthy string, separated by double pipes "||", I'm not sure what the next step would be.

        How do I translate each of those 36 character values, ignoring the pipes, using the matching link_attributes column of each service's pagetitle?

        Whatever that SQL command is, I assume that I would add that as another LEFT JOIN command in my SQL config file?
          • 53460
          • 69 Posts
          Hold on, scratch Reply #3. I think I have a different question. I'll post it when I've thought it out.
            • 46886
            • 1,154 Posts
            I think this long code issue might not be where you want to go. I know you are doing yeoman's work now so pls take all comments as advice, whether on-point or not.

            link_attributes gives you the output, that's what you need, the little code machine that will output what you want, its name seems to be link_attributes, that little code that coughs up the data about practice areas.

            When the page template fires, that snippet which is **under** the text "Related Services and Industries" queries the database and returns those 'practice areas' values. The title is meaningless really, the key issue is the tool underneath in the html, that is what you want to utilize.

            Now, if I am not mistaken, because that page has fired, all the values from that tool should be in Modx memory, and you can invoke them. So if that tool defines a term as say practice_field and sets a value for that (its an array of returned values I suppose), you could just tell Modx to pull that value into what you want to do next, activated by the search button. That's part of Modx's secret sauce

            You could also obviously copy the tool and sort of paste it into your search routine...maybe. You could run the tool a second time when search is pressed, then throw the output of that into the next routine. So you've got a lot of ways to work this out.

            There are I guess some issues about when things happen...if the new page (the search page) loaded first then you might lose those values.

            You are really close here. The data is in one place but just needs to be ported to the search function