1

I have a very straightforward ContentSearch issue.

My code is as follows:

var filter = PredicateBuilder.True<PersonObject>();
filter = filter
   .And(i => i.Email == "my.email@address.com");

(...standard ContentSearch code follows...)

Where the Email field is defined as:

[IndexField("email_t")]
public virtual string Email { get; set; }

The index is populated correctly: going on the SOLR web interface and performing the following query:

query?q=email_t:"my.email@address.com"

results in the one record with said email address being correctly returned.

Interestingly enough, the Search.log has this entry associated to the above search:

?q=email_t:(my.email@address.com)&rows=1&fl=*,score&fq=_indexname:(sitecore_web_index)&wt=xml&sort=sortorder_tl asc

Which sounds pretty much spot-on. So why this search is returning every single *PersonObject* and not just the one with the specified email?

QUESTION(s)

What am I doing wrong that is causing multiple results to be returned? Are the information I provided enough to troubleshoot this issue?

  • If I recall, it has to do with tokenization of the contents of that field. So when you issue a search for my.email@address.com, internally Solr is searching for my, email, address, and com. Which would return (almost) everything because most email addresses probably have com in them. We resolved this issue by creating a custom computed field for emails (which apparently doesn't get tokenized) that just stores the email value and searching against that field intead. – Dan Sinclair Sep 30 at 19:25
4

This is how text fields work, it's a tokenized search.. If you are looking for an exact string match, you should be using returnType="string" in your index configuration. Beware as well that you should not be using _t in your code as that hardcodes the Solr field type. You should also change that in your code to just [IndexField("email")]. This should be all you need.

  • Do I have to specifically declare email (or email_s) as part of the index configuration? – Emanuele Ciriachi Sep 30 at 21:11
  • This worked for me - I only had to add <field fieldName="email" returnType="string" storageType="yes">MyProject.ComputedFields.ParsedValue, MyProject</field> to my custom IndexConfiguration. – Emanuele Ciriachi Sep 30 at 21:42
  • @EmanueleCiriachi Ah yes. It is always best to explicitly specify the returnType. Also, never specify the suffix as Sitecore will determine it automatically for you. email is sufficient (not _s or _t). – Matthew FitzGerald-Chamberlain Sep 30 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.