Answers.Body: <p>I can't think of a way to easily alter the search in all cases (quick search, autocomplete, normal search...</p>
  
  <p>What we usually do when we have to store organisational units is to create a new contact type (department) and store together the org+"|"+dep as the organisation name. </p>
  
  <p>if this is a matter of making it easier to input the departments in that format or tweak some reports, you can still keep a separate field for the department and alter the organisation name via the hook, or split the organisation name on the "|" to separate the university from the department.</p>
  
  <p>From a data modelling point of view, it won't win any beauty contest, but does the job. and it's more or less what's happening with the individuals, where first and last names are separate columns that are concatenated into the sort_name and display_name. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-21T09:02:15.840Z
Answers.Text: What is the new contact type for? How do you make use of it?
Answers.UserDisplayName: nielo
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-21T09:06:38.723Z
Answers.Text: the new contact type would be a subtype of "organisation" and to make it clearer for everyone (user or custom code if needed) that the format of the organisation name is "special".
Answers.UserDisplayName: Xavier
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-21T08:59:29.977Z
Answers.LastActivityDate: 2016-01-21T08:59:29.977Z
Answers.UserDisplayName: Xavier
Body: <p>How would it be possible to hook into civi's searches to always lookup a custom field when searching for name?</p>
  
  <p>Background:
  In our setup we handle big departments as distinct contacts. Their name is the base organization name and we provide a custom field "Additional name" in which the department's name is stored. </p>
  
  <p>Example:</p>
  
  <pre><code>Contact A: Base Organization named "University of Bielefeld",
  Contact B: Department of A named "University of Bielefeld" with
             additional name "Faculty of Physics"
  Contact C: Department of A named "University of Bielefeld" with
             additional name "FooBar Institute"
  </code></pre>
  
  <p>We do this for different reasons, for instance because pdf letter addressing is simpler.</p>
  
  <p>Problem: If our users head over to search box, advanced search or simple search and fill the name or name/email field  with "foobar", they don't get correct results. </p>
  
  <p>Any ideas?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-20T14:44:40.233Z
Comments.Text: Are you part of the Bielefeld conspiracy? the answer is simple: there is no university there, it has no department, and that city doesn't exist ;)
Comments.UserDisplayName: Xavier
Tags: <custom-fields><search><custom-search>
Title: Extending default search for name to consult a custom field
ThreadText: # Extending default search for name to consult a custom field
  
  (Asked by: username_0 on 2016-01-20)
  
  How would it be possible to hook into civi's searches to always lookup a custom field when searching for name?
  Background:
  In our setup we handle big departments as distinct contacts. Their name is the base organization name and we provide a custom field "Additional name" in which the department's name is stored. 
  Example:
  Contact A: Base Organization named "University of Bielefeld",
  Contact B: Department of A named "University of Bielefeld" with
             additional name "Faculty of Physics"
  Contact C: Department of A named "University of Bielefeld" with
             additional name "FooBar Institute"
  
  We do this for different reasons, for instance because pdf letter addressing is simpler.
  Problem: If our users head over to search box, advanced search or simple search and fill the name or name/email field  with "foobar", they don't get correct results. 
  Any ideas?
  
  **Tags:** custom-fields, search, custom-search
  
  > **Comments:**
  > **username_1**: Are you part of the Bielefeld conspiracy? the answer is simple: there is no university there, it has no department, and that city doesn't exist ;)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-01-21. Score: 1 | Accepted answer
  
  I can't think of a way to easily alter the search in all cases (quick search, autocomplete, normal search...
  
  What we usually do when we have to store organisational units is to create a new contact type (department) and store together the org+"|"+dep as the organisation name.
  
  if this is a matter of making it easier to input the departments in that format or tweak some reports, you can still keep a separate field for the department and alter the organisation name via the hook, or split the organisation name on the "|" to separate the university from the department.
  
  From a data modelling point of view, it won't win any beauty contest, but does the job. and it's more or less what's happening with the individuals, where first and last names are separate columns that are concatenated into the sort\_name and display\_name.
  
  > **Comments:**
  > **username_0**: What is the new contact type for? How do you make use of it?  
  > **username_1**: the new contact type would be a subtype of "organisation" and to make it clearer for everyone (user or custom code if needed) that the format of the organisation name is "special".  
  
  ---
  
  