Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Account Search Wildcard

  1. #1
    madcoder1988 is offline Senior Member
    Join Date
    Aug 2010
    Posts
    34

    Default Account Search Wildcard

    Hi,

    Could anyone point me to how I can do a wildcard search on the accounts section.

    I've tried changing www\modules\Accounts\Accounts.php with no luck.

    Can anyone point me in the right direction.

    Thanks.

  2. #2
    sts's Avatar
    sts
    sts is offline Sugar Community Member
    Join Date
    Aug 2010
    Posts
    978

    Default Re: Account Search Wildcard

    You can use "%" as a wildcard (see screenshot).
    Attached Images Attached Images  
    Stefan Ulrich Sauer
    System Analyst

    Devoteam Danet GmbH
    Gutenbergstraße 10
    D-64331 Weiterstadt
    Germany
    email: Stefan-Ulrich.Sauer@devoteam.com
    http://www.devoteam.de

  3. #3
    madcoder1988 is offline Senior Member
    Join Date
    Aug 2010
    Posts
    34

    Default Re: Account Search Wildcard

    Hi,

    I wanted to change it by default in the code - could you let me know how I can do this?

  4. #4
    sts's Avatar
    sts
    sts is offline Sugar Community Member
    Join Date
    Aug 2010
    Posts
    978

    Default Re: Account Search Wildcard

    Default is a search with wildcard at the end. Searching for "%something%" is the same as "%something".
    You can place %-Wildcards everywhere in the searchstring, e.g. "%som%thing".

    What kind of wildcard-search would you like to have instead?
    Stefan Ulrich Sauer
    System Analyst

    Devoteam Danet GmbH
    Gutenbergstraße 10
    D-64331 Weiterstadt
    Germany
    email: Stefan-Ulrich.Sauer@devoteam.com
    http://www.devoteam.de

  5. #5
    madcoder1988 is offline Senior Member
    Join Date
    Aug 2010
    Posts
    34

    Default Re: Account Search Wildcard

    Hi,

    I want to change in the code the wildcard search, so by default it searchs %searchterm% how can I do this?

  6. #6
    robertbmirth is offline Sugar Community Member
    Join Date
    Jun 2010
    Location
    Irvine, CA
    Posts
    345

    Default Re: Account Search Wildcard

    I'm not sure if there's a better way to do this (there probably is), but you can get into the search queries via the view.list.php file (either the root one, at include/MVC/View/views, which modification of would not be upgrade safe, or at each module you'd like the search to modify, found at custom/modules/<module_name>/views). If you look through the processSearchForm() function, you should be able to find enough information there to be able to modify all the where clauses in your search query (the clauses are actually stored in a variable called $where_clauses i think) and search on your modified where clauses.
    Robert Beckman
    Software Engineer
    Mirth Corporation

  7. #7
    madcoder1988 is offline Senior Member
    Join Date
    Aug 2010
    Posts
    34

    Default Re: Account Search Wildcard

    Strange, cant seem to find any function called processSearchForm()

    I've checked the where clauses in custom/modules/<module_name>/views and I modified the one for the accounts section, but for some reason it has no impact!

  8. #8
    madcoder1988 is offline Senior Member
    Join Date
    Aug 2010
    Posts
    34

    Default Re: Account Search Wildcard

    n /modules/accounts/accounts.php there is a statement ...

    array_push($where_clauses, "accounts.name like '%$the_query_string%'");

    which I have changed to incorporate an extra % at the start - this doesn't seem to have done anything though!

  9. #9
    robertbmirth is offline Sugar Community Member
    Join Date
    Jun 2010
    Location
    Irvine, CA
    Posts
    345

    Default Re: Account Search Wildcard

    The reason it may not have an impact is because the actual variable that passes the where clause to your query is your ViewList::where variable, but I found that the best way to modify this is before it gets imploded and its still in the $where_clause form in the processSearchForm() function.

    I have version 6.0 Pro of SugarCRM, and in my include/MVC/View/views/view.list.php there's the function:
    PHP Code:
    function processSearchForm(){
             if(isset(
    $_REQUEST['query']))
            {
                
    // we have a query
                
    if(!empty($_SERVER['HTTP_REFERER']) && preg_match('/action=EditView/'$_SERVER['HTTP_REFERER'])) { // from EditView cancel
                    
    $this->searchForm->populateFromArray($this->storeQuery->query);
                }
                else {
                    
    $this->searchForm->populateFromRequest();
                }   

                
    $where_clauses $this->searchForm->generateSearchWhere(true$this->seed->module_dir);

    //ADD MODIFICATIONS HERE

                
    if (count($where_clauses) > )$this->where '('implode(' ) AND ( '$where_clauses) . ')';
                
    $GLOBALS['log']->info("List View Where Clause: $this->where");
            }
            if(
    $this->use_old_search){
                switch(
    $view) {
                    case 
    'basic_search':
                        
    $this->searchForm->setup();
                        
    $this->searchForm->displayBasic($this->headers);
                        break;
                     case 
    'advanced_search':
                        
    $this->searchForm->setup();
                        
    $this->searchForm->displayAdvanced($this->headers);
                        break;
                     case 
    'saved_views':
                        echo 
    $this->searchForm->displaySavedViews($this->listViewDefs$this->lv$this->headers);
                       break;
                }
            }else{
                echo 
    $this->searchForm->display($this->headers);
            }
         } 
    You can copy this function, along with any modifications to your $where_clauses and/or $this->where (I'd suggest modification of the $where_clauses where I've put the comment, however, because you don't want to wildcard everything, i.e. wildcarding an integer field is going to give you an error i believe) into whatever custom file you're creating, or you can just make the modifications into the root file (back it up first). For me, the function starts on line 244.
    Robert Beckman
    Software Engineer
    Mirth Corporation

  10. #10
    madcoder1988 is offline Senior Member
    Join Date
    Aug 2010
    Posts
    34

    Default Re: Account Search Wildcard

    Hi Rob,

    So I just need to add code as follows?

    How exactly can I modify it to do a LIKE statement?

    $where_clauses[0] = '%' . $where_clauses[0] . '%'

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Hard Coding Wildcard for Search
    By Rjrobinson in forum Help
    Replies: 6
    Last Post: 2011-08-03, 09:46 AM
  2. Replies: 0
    Last Post: 2010-12-07, 07:02 AM
  3. Unable to search unified search with prepended wildcard
    By jbeauchamp in forum Developer Help
    Replies: 0
    Last Post: 2010-11-30, 03:02 PM
  4. Lead Search >> account name searches account module in 5.0!
    By lowJack01 in forum Installation and Upgrade Help
    Replies: 0
    Last Post: 2008-06-11, 05:12 PM
  5. force sugar to do a Wildcard search in 4.2.1b
    By audiopleb in forum Developer Help
    Replies: 3
    Last Post: 2006-08-24, 12:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •