CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • Search String Bugs
Pages: [1]

Author Topic: Search String Bugs  (Read 1743 times)

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Search String Bugs
September 24, 2007, 11:54:59 am
Hi,

I have a record in Civicrm for an organization called "City of Burlington". I also have a different record for a different organziation called "Burlington City" (yes, seems the same, but they are different). When I type "City of Burlington" into the CiviCRM search string box, I get 22 results, and both of the above mentioned show up. I also get results for other organizations just called "Burlington"; I get anything and everything that has the word "Burlington" in it, even though I typed in "City of Burlington".

When I type "Burlington" into the search string box, I get 18 results. It does not return any results that don't start with the word "Burlington"; thus "City of Burlington" does not show up.

These seems like very conflicting search results in terms of the search strings. I would expect that all 22 results would show up for the search on "Burlington", and the more restricted results to show up for the "City of Burlington" search. When in fact it is the other way around. I would appreciate any insight on this buggy behavior.

Thanks,
Emily

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Search String Bugs
September 24, 2007, 02:17:33 pm
The string search algorithm takes each "word" in the string and appends a wild-card (%) after the word. Then it does an OR search on these elements.

So, a search for "City of Burlington" becomes:

SELECT .... WHERE sort_name LIKE 'city%' OR sort_name LIKE 'of%' OR sort_name LIKE 'burlington%'

This works pretty well for searches on peoples names ("Smith, Jane") - perhaps less well for multi-word organization names. We will be revisiting these rules/algorithms in 2.1.

For now, if you want the search to return items which contain (but don't start with) your search string - you'll need to prepend the string with the wildcard (%). So, to find organizations which contain 'Burlington' - search for '%Burlington'.

The search algorithm will automatically lower-case your string and append the wildcard to all "words" - so this will result in:

SELECT ... WHERE sort_name LIKE '%burlington%'

Protect your investment in CiviCRM by  becoming a Member!

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: Search String Bugs
September 28, 2007, 05:52:50 am
Thanks, Dave. It's getting clearer in my murky brain. By typing %burlington I now get 28 results. So here's my next question. From the way I read your response, it seems like if I typed in

%city of burlington

then I would get results for anything containing any one of those three words in no particular order. So in my mind, that would technically mean I should get at least as many results as the %burlington search, if not more. However, I only get 19 results. Am I still not getting it?

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Search String Bugs
September 28, 2007, 10:31:19 am
"%city of burlington" will produce this SELECT statement:

SELECT .... WHERE sort_name LIKE '%city%' OR sort_name LIKE 'of%' OR sort_name LIKE 'burlington%'

This will return names which contain 'city' regardless of what the starting characters/words are. As well as names which start with 'burlington' OR start with 'of'.

while "%burlington" gives you:

SELECT .... WHERE sort_name LIKE  '%burlington%'

This will return names which contain 'burlington' regardless of what the starting character/words are.

So the difference results are related to which word(s) have the wildcard at the beginning (which you put in manually) as well as at the end (which are put in automatically). Hope that helps.
Protect your investment in CiviCRM by  becoming a Member!

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Search String Bugs
September 28, 2007, 11:53:16 am

This does not help you right now :(, but 2.0 allows you to enter quotes for the entire search string. Thus: "City of Burlingame" will only find entries matching that complete phrase

In the long run, CiviCRM should integrate with a full featured search engine like Solr/Lucene. Thats a more scalable powerful search than relying on mysql LIKE and boolean operators :)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: Search String Bugs
January 28, 2010, 11:16:31 am
Howdy

Long time since I updated this post. Is a Civi integration with Solr in the works? Is there a way to pull this in through Drupal's integration with it?

I ask this because I'm getting back to this original issue, but now with 3.0. Still having a bunch of issues. Trying to understand what's going on.

I have an organization, let's say "AA Jeans". This org has no email associated with it. Then I have a bunch of households also as "AA Jeans" without emails. Then I have a bunch of employees who work there, all with email address like "x@aajeans.com".

So when I type "=AA Jeans" (no quotes) into the search box, I get all of these results. This is excellent.

Second example. I have an organization called "Region Sports". There is no email associated with it. I have a bunch of households also as "Region Sports". and of course, employees with "@regionsports.com". Now, when I type '=Region Sports' into the search, I get tons of results, anything with 'sports' in the name.

According to our discussion above, I'm assuming this is because I have other contacts in my db with the word 'sports' in their name, while I must not have any other contacts in my db with the word 'jeans' in their name. Am I correct?

Sadly, the whole double quotes thing is great except that it is too restrictive in my case. Meaning, because I might not have emails with my orgs and households, if I type "Region Sports" with the quotes into the search box, then it's only going to give me the organization. Where as if I type "regionsports" into the search box, it only gives me the individuals who work there (because of email addresses) and not the organization/households themselves.

This appears to be driving my staff crazy. Is there search/report I could build off to basically let you type in an org name and have it display search results for any and all relationships, including the main org? I was trying to do an advanced search and see if the 'belongs to' or 'includes' options under relationships might do this, but it also appears to restrict to one particular contact type (household OR individual, but not both). Also looking under reports, but I can tell my staff will find filling them out complicated and too much work. Trying to find some easy way to get this information in some kind of search.

A lot of information here. I'm looking for general input, suggestions, help, or pointers to where this is at now that we're at 3.0.

Thanks so much.
emilyf

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Search String Bugs
January 28, 2010, 12:35:36 pm

solr integration is in the works. dont know if/when/how it will integrate with drupal (probably not in the early releases). i suspect it will be released as in a future 3.1.x

however i dont think your issues will be solved by solr integration

if you want flexible name searching as you described below, your best bet might be to write a custom search and implements the rules below. custom search development is documented here:

http://wiki.civicrm.org/confluence/display/CRMDOC/Custom+Search+Components

lobo

A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: Search String Bugs
January 28, 2010, 12:53:36 pm
thanks lobo; i figured you'd say that  ;D

will keep a watch on solr as well as that will be quite the improvement in other areas. for anyone else interested, here's another good thread on searching: http://forum.civicrm.org/index.php/topic,6241.0.html

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • Search String Bugs

This forum was archived on 2017-11-26.