RSS

Monthly Archives: December 2013

2013 in review

The WordPress.com stats helper monkeys prepared a 2013 annual report for this blog.

Here’s an excerpt:

The concert hall at the Sydney Opera House holds 2,700 people. This blog was viewed about 34,000 times in 2013. If it were a concert at Sydney Opera House, it would take about 13 sold-out performances for that many people to see it.

Click here to see the complete report.

 
Leave a comment

Posted by on December 31, 2013 in Uncategorized

 

Set uniqueKey field out of string or uuid

By Sochinda

Open file called: solrconfig.xml and disable

<!--
<searchComponent name="elevator" >
    <str name="queryFieldType">string</str>
    <str name="config-file">elevate.xml</str>
</searchComponent>
-->
 
Leave a comment

Posted by on December 30, 2013 in Solr

 

Mapping Object Attribute in SolrNet

By: 

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.

Example:

public class Product {
    [SolrUniqueKey("id")]
    public string Id { get; set; }

    [SolrField("manu_exact")]
    public string Manufacturer { get; set; }

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

    [SolrField("price")]
    public decimal Price { get; set; }

    [SolrField("inStock")]
    public bool InStock { get; set; }

    [SolrField("timestamp")]
    public DateTime Timestamp { get; set; }

    [SolrField("weight")]
    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.

All-properties

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();
mapper.SetUniqueKey(typeof(Product).GetProperty("id"));

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.SetUniqueKey(property);
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:

[SolrField("price_i")]
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:

[SolrField("price_")]
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:

[SolrField("*")]
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: https://github.com/mausch/SolrNet/blob/master/Documentation/Mapping.md

 
2 Comments

Posted by on December 30, 2013 in Solr

 

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\jasperreports.properties and copy bellow text pas into this file and save

net.sf.jasperreports.query.executer.factory.xpath2=com.jaspersoft.jrx.query.JRXPathQueryExecuterFactory

– 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}

 

 
Leave a comment

Posted by on December 6, 2013 in JasperReport

 

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" />



http://stackoverflow.com/questions/11494200/can-periods-be-used-in-asp-net-web-api-routes
 
Leave a comment

Posted by on December 5, 2013 in Web API ASP.NET