LibrarySites.Banner

Sitecore 7 Special Queries

Sitecore.ContentSearch Special Queries

There will most likely not be a lot of places where you will need to run these types of queries however every project has its oddities and we aim to provide as many search solutions as possible.

Regular Expression Support with LINQ

It may be required that you need to run Regular Expression queries with the new LINQ layer and the good news we have this covered for you and also in a scalable manner as well. Here are some examples of how you could achieve what you are after.

    public void Match_All_Regular_Expression()
    {
        IQueryable<SearchResultItem> q = queryable.Where(i => i.Template.Matches("^.*$"));    
    }

    public void Match_Extension()
    {
        IQueryable<SearchResultItem> q = queryable.Where(i => i.Template.Matches("^.*ar(d|t).*$")); 
    }

    public void Match_Extension_With_Options()
    {
        IQueryable<SearchResultItem> q = queryable.Where(i => i.Template.Matches("^.*AR(d|t).*$", RegexOptions.IgnoreCase));
    }

Fuzzy Search Support with LINQ

It may be required that you need to run Fuzzy or Similarity queries with the new LINQ layer and the good news we have this covered for you as well. Here are some examples of how you could achieve what you are after.

    public void Fuzzy_With_Similarity()
    {
         IQueryable<SearchResultItem> q  = queryable.Where(i => i.Template.Like("Holdåhl", 0.3f)).OrderBy(d => d.Id);
    }

    public void Fuzzy_No_Similatiry()
    {
        IQueryable<SearchResultItem> q = queryable.Where(i => i.Template.Like("Holdåhl")).OrderBy(d => d.Id);
    }

    public void Fuzzy_With_Phrase()
    {
        IQueryable<SearchResultItem> q = queryable.Where(i => i.Template.Like("Ran McNalle", 10)).OrderBy(d => d.Id);
    }

As we add more types of query support for unique requirements we will add them here. We plan on adding queries such as "More Like This", "Span Query" and "Spatial Queries".

  • Dev Team