Skip to content

Linq provider to solrnet

oshvartz edited this page Nov 12, 2011 · 4 revisions

#Linq Provider to Solrnet

How To Use

In order to use just add: using SolrNet.LINQ; and for ISolrBasicReadOnlyOperations<T> you can write AsQueryable() getting the IOrderedQueryable<TData> object.

Supporting the following features:

  1. Equals:

var linqQuery = from doc in solr.AsQueryable() where doc.Name == "aa" select doc;`

  1. Greater/Smaller Equals

var linqQuery = from doc in solr.AsQueryable() where doc.Price >= 1 && doc.Price <= 10 select doc;

  1. Not Operator var linqQuery = from doc in solr.AsQueryable() where !(doc.Name == "bb") select doc;

  2. DefaultField Equals query:

var linqQuery = from doc in solr.AsQueryable() where doc.DefaultFieldEquals("aa") select doc;

  1. AND / OR:

var linqQuery = from doc in solr.AsQueryable() where doc.DefaultField("aa") && (doc.Price >= 1 || doc.Price <= 11) select doc;

  1. Partial Eval

        `int priceVal = 1;
         DateTime dt = new DateTime(2011, 1, 1);
         var linqQuery = from doc in solr.AsQueryable()
                         where (doc.Price >= priceVal || doc.Timestamp >= dt)
                         select doc;`
    
  2. Pagination

var linqQuery = (from doc in solr.AsQueryable() where (doc.Price >= priceVal || doc.Timestamp >= dt) select doc).Pagination(10,15);

  1. Sort

var linqQuery = from doc in solr.AsQueryable() where (doc.Price >= priceVal || doc.Timestamp >= dt) orderby doc.Id, doc.Price descending select doc;

  1. Boost

     `var linqQuery = from doc in solr.AsQueryable()
                         where (doc.Name == "john").Boost(10)
                         select doc;`
    
  2. Collection Query – Single

    var linqQuery = from doc in solr.AsQueryable() where doc.Categories.AnyItem() == "cat1" select doc;

  3. AdditinalParameters

var linqQuery = (from doc in solr.AsQueryable() where (doc.Price >= priceVal || doc.Timestamp >= dt) select doc).AdditinalParameters(new Dictionary<string,string>{{ "queryduration","100"}};

  1. dynamic fields

var linqQuery = from doc in solr.AsQueryable() where doc.DynamicField("field_1") == "val" select doc;

Clone this wiki locally