public override IFacet CreateFacet(FacetMoniker moniker)
 {
     try
     {
         var ci = ContactInfo.FromXml(moniker.FactoryData);
         return(new ContactFacet(ci.DisplayName, ci.Email));
     }
     catch (Exception)
     {
         return(null);
     }
 }
        public override bool CanCreateFacet(FacetMoniker moniker)
        {
            try
            {
                // TODO: this is not fast
                ContactInfo.FromXml(moniker.FactoryData);
                return(true);
            }
            catch (Exception)
            {
            }

            return(false);
        }
        protected override IEnumerable <ParseResult> ParseImpl(ParseInput input, IEnumerable <FacetMoniker> indexEntries)
        {
            foreach (var entry in indexEntries)
            {
                var ci = ContactInfo.FromXml(entry.FactoryData);

                var relevance = 0.0;

                ParseRange firstNameRange = null;
                ParseRange lastNameRange  = null;
                ParseRange emailRange     = null;

                foreach (var term in input.Terms)
                {
                    if (firstNameRange == null)
                    {
                        if (ApplyRelevance(ref relevance, ci.FirstName, term.TextLower) > 0)
                        {
                            firstNameRange = term.Range;
                            continue;
                        }
                    }

                    if (lastNameRange == null)
                    {
                        if (ApplyRelevance(ref relevance, ci.LastName, term.TextLower) > 0)
                        {
                            lastNameRange = term.Range;
                            continue;
                        }
                    }

                    if (emailRange == null)
                    {
                        if (ApplyRelevance(ref relevance, ci.Email, term.TextLower) > 0)
                        {
                            emailRange = term.Range;
                            continue;
                        }
                    }
                }

                if (relevance == 0.0 ||
                    ((firstNameRange != null && lastNameRange != null) &&
                     lastNameRange.StartIndex <= firstNameRange.StartIndex))
                {
                    continue;
                }

                // determine the input range that caused the match
                ParseRange range;

                if (firstNameRange != null)
                {
                    if (lastNameRange != null)
                    {
                        range = firstNameRange.Union(lastNameRange);
                    }
                    else
                    {
                        range = firstNameRange;
                    }
                }
                else if (lastNameRange != null)
                {
                    range = lastNameRange;
                }
                else
                {
                    range = emailRange;
                }

                yield return(new ParseResult(input, range, entry, relevance));
            }
        }