Mapping Object Attribute in SolrNet


Solr fields defined in your schema.xml must be mapped to properties in a .NET class. There are currently three built-in ways to map fields:

Attributes (default)

With this method you decorate the properties you want to map with the SolrField and SolrUniqueKey attributes. The attribute parameter indicates the corresponding Solr field name.


public class Product {
    public string Id { get; set; }

    public string Manufacturer { get; set; }

    [SolrField("cat")] // cat is a multiValued field
    public ICollection<string> Categories { get; set; }

    public decimal Price { get; set; }

    public bool InStock { get; set; }

    public DateTime Timestamp { get; set; }

    public double? Weight { get; set;} // nullable property, it might not be defined on all documents.

This way of mapping is implemented by the AttributesMappingManager class.

Index-time field boosting

You can also use the mapping attribute to apply a boost to a specific field at index-time.

[SolrField("inStock", Boost = 10.5)]
public bool InStock { get; set; }

.. this will add a boost of 10.5 to the InStock field each time the document is indexed.


This maps each property of the class to a field of the exact same name as the property (note that Solr field names are case-sensitive). It’s implemented by the AllPropertiesMappingManager class. Note that unique keys cannot be inferred, and therefore have to be explicitly mapped. The same mapping as above could be accomplished like this:

public class Product {
    public string id { get; set; }
    public string manu_exact { get; set; }
    public ICollection<string> cat { get; set; }
    public decimal price { get; set; }
    public bool inStock { get; set; }
    public DateTime timestamp { get; set; }
    public double? weight { get; set; }

Then to add the unique key:

var mapper = new AllPropertiesMappingManager();

Manual mapping

This allows you to programmatically define the field for each property:

public class Product {
    public string Id { get; set; }
    public string Manufacturer { get; set; }
    public ICollection<string> Categories { get; set; }
    public decimal Price { get; set; }
    public bool InStock { get; set; }
    public DateTime Timestamp { get; set; }
    public double? Weight { get; set; }
var mgr = new MappingManager();
var property = typeof (Product).GetProperty("Id");
mgr.Add(property, "id");
mgr.Add(typeof(Product).GetProperty("Manufacturer"), "manu_exact");
mgr.Add(typeof(Product).GetProperty("Categories"), "cat_exact");
mgr.Add(typeof(Product).GetProperty("Price"), "price");
mgr.Add(typeof(Product).GetProperty("InStock"), "inStock");
mgr.Add(typeof(Product).GetProperty("Timestamp"), "timestamp");
mgr.Add(typeof(Product).GetProperty("Weight"), "weight");

Dictionary mappings and dynamic fields

Solr dynamicFields can be mapped differently depending on the use case. They can be mapped “statically”, e.g, given:

<dynamicField name="price_*"  type="integer"  indexed="true"  stored="true"/>

a particular dynamicField instance can be mapped as:

public decimal? Price {get;set;}

However, it’s often necessary to have more flexibility. You can also map dynamicFields as a dictionary, with a field name prefix:

public IDictionary<string, decimal> Price {get;set;}

In this case, price_ is used as a prefix to the actual Solr field name, e.g. with this mapping, Price["regular"] maps to a Solr field named price_regular.

Another, even more flexible mapping:

public IDictionary<string, object> OtherFields {get;set;}

This acts as a catch-all container for any fields that are otherwise unmapped. E.g. OtherFields["price_i"] maps to a Solr field named price_i.

Fully loose mapping

An even more “dynamic” mapping can be achieved by using a Dictionary<string,object> as document type. In this document type, the dictionary key corresponds to the Solr field name and the value to the Solr field value. Statically typing the fields is obviously lost in this case, though.

When adding documents as Dictionary<string,object> SolrNet will recognize field value types as usual, e.g. you can use strings, int, collections, arrays, etc. Example:

Startup.Init<Dictionary<string, object>>(serverUrl);
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Dictionary<string, object>>>();
solr.Add(new Dictionary<string, object> {
  {"field1", 1},
  {"field2", "something else"},
  {"field3", new DateTime(2010, 5, 5, 12, 23, 34)},
  {"field4", new[] {1,2,3}},

When fetching documents as Dictionary<string,object> SolrNet will automatically map each field value to a .NET type, but it’s up to you to downcast the field value to a properly typed variable. Example:

ISolrOperations<Dictionary<string, object>> solr = ...
ICollection<Dictionary<string, object>> results = solr.Query(SolrQuery.All);
bool inStock = (bool) results[0]["inStock"];

Custom mapping

You can code your own mapping mechanism by implementing the IReadOnlyMappingManager interface.

To override the default mapping mechanism, see this page.


Copy from:

Building Report Server in Jasperreport Server

By: Sochinda Tith

JasperRetport Server

JasperReports Server is a stand-alone and embeddable reporting server. It provides reporting and analytics that can be embedded into a web or mobile application as well as operate as a central information hub for the enterprise by delivering mission critical information on a real-time or scheduled basis to the browser, mobile device, printer, or email inbox in a variety of file formats. JasperReports Server is optimized to share, secure, and centrally manage your Jaspersoft reports and analytic views.

Requirement Download and Install:

  1. JDK/JRE
  2. JasperReport Server
  3. iReport
  4. JasperSoft Studio
  5. Web Service that return as XML (URL Data Access)

JasperReport Preparation

– Go to iReport installed and copy from path: ..\ireport\modules\ext\jasperreports-extensions-3.5.3.jar to JasperReport Server path: ..\apache-tomcat\webapps\jasperserver\WEB-INF\lib\jasperreports-extensions-3.5.3.jar

– Go to file in :..\apache-tomcat\webapps\jasperserver\WEB-INF\classes\ and copy bellow text pas into this file and save


– Restart Tomcat

Report Preparation

Create and design report using XML Remote as datasource

And export into Jasper Report Server

You should see a window like this:

Now you can start Jaspersoft Studio. Click the Repository Explorer tab, then select Create a JasperReports Server Connection.

A dialog to insert the server data appears. Fill it in as follows:

  • Name: the name of the connection. You can use any name you want. For this example we will leave the default name: JasperReports Server.
  • URL: the address of the server. The default address is already correct if we are using a local server. For this example the correct address is http://localhost:8080/jasperserver/services/repository.
  • User: the username to access the server. The default for the local server is “jasperadmin”.
  • Password: as with the username, for the local server by default it is “jasperadmin”.

Then click the Test Connection button to test the connection. If everything is working, click Finish.

Now you are connected to the server and you can upload and download reports.

Publishing a Report on JasperReports Server

For this section,  we will use the one created during the tutorial Report Structure in Jaspersoft Studio. Open the report and click the button with a blue arrow in the upper-right corner of the designer. In the opened window you can browse the server directory structure to choose where to place the report. Select the Reports folder as in the image above. Name the report unit you are creating to contain all the files for the report we are uploading (for this example we can use “ColumnsSample”). Then click Next.

In the next step we have to handle the data source. Exporting a report is quite simple, but exporting the data source used to fill the report it isn’t so trivial. For exporting the data source we have three options:

  • Data source from repository: the server will use a data source already there it to fill the report, so we will only need to browse the server until we find the wanted data source.
  • Local data source
  • Don’t use any data source: only the report is exported without any data source connection

We will use the third option, which is the default one, and click Finish. The report is uploaded to the server and, if there are no errors, an appropriate message will be shown.

Call Report from JasperReport Server

Enter in url: http://{hostname}:{port}/jasperserver/flow.html?_flowId=viewReportFlow&reportUnit=/reports/Test/A4Test&standAlone=true&ParentFolderUri=/reports/Test&XML_URL={Webservice Url}


Get Error 404 for using UriFormatExtension in WebAPI

I was able to achieve this by doing the following: replace "*." with "*" in system.webServer.handlers in web.config, i.e. remove the period.

<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />