solr express
Search…
Getting started
To start to use SolrExpress, just follow follow steps:
    1.
    Create a class to represent your collection, extend Document class and use attributes to indicate Solr fields.
1
public class TechProductDocument : Document
2
{
3
[SolrField("manu")]
4
public string Manufacturer { get; set; }
5
6
[SolrField("store")]
7
public GeoCoordinate StoredAt { get; set; }
8
}
Copied!
    1.
    Choose your favorite Dependency Injection provider (SolrExpress.DI.Autofac, SolrExpress.DI.CoreClr, SolrExpress.DI.Ninject or SolrExpress.DI.SimpleInject) and add reference to package
    2.
    Add reference to correct Solr provider (SolrExpress.Solr4 or SolrExpress.Solr5)
    3.
    Configure SolrExpress setting Solr host address for each collection
1
public void ConfigureServices(SomeDIContainer services)
2
{
3
services
4
// This extension is from SolrExpress.DI.<Your favorite DI provider>
5
.AddSolrExpress<TechProduct>(builder => builder
6
.UseHostAddress("http://localhost:8983/solr/techproducts")
7
// This extension is from SolrExpress.Solr5
8
.UseSolr5()); // Or UseSolr4 from SolrExpress.Solr4
9
}
Copied!
    1.
    Configue search parameters, execute, read results and enjoy :)
1
using SolrExpress.Search.Parameter.Extension;
2
3
public void MyAmazingSearch(DocumentCollection<TechProduct> techProducts)
4
{
5
// Initial search settings (configure to result facet field Categories and filter by field id using value "205325092")
6
var searchResult = techProducts
7
.Select()
8
.Fields(d => d.Id, d => d.Manufacturer)
9
.FacetField(d => d.Categories)
10
.Filter(d => d.Id, "205325092")
11
.Execute();
12
13
// Get general information about search, documents and facets from search result
14
searchResult
15
.Information(out var information)
16
.Document(out var documents)
17
.Facets(out var facets);
18
}
Copied!
NOTES
    1.
    Class TechProductDocument represents a document in Solr collection and to be easy to identitify this, I call this class with the same name of the Solr collection (techproducts) but you can choose any name what you want, just remember, extends Document class;
    2.
    To example purposes, I set collection address in hard code.
Last modified 2yr ago
Copy link