Searching in Apache Solr with Solr4j


We will describe a function for searching in Apache Solr –

 
public static Map searchIndexSolr(String searchString) throws Exception {
    //Instantiate the Apache Solr Server
    SolrServer solr = new CommonsHttpSolrServer("http://localhost:8983/solr");

    ModifiableSolrParams params = new ModifiableSolrParams();

    //Setting the Search Parameter
    params.set("q", searchString);

    //Response from Solr Server
    QueryResponse response = solr.query(params);

    //Convert response to Solr Documents
    SolrDocumentList docs = response.getResults();

    Iterator iter = response.getResults().iterator();
    ArrayList catString = new ArrayList();

    ArrayList categories = null;

    boolean firstDoc = false;

    //Iterate over the Solr Documents	    
    while (iter.hasNext()) {
      SolrDocument resultDoc = iter.next();
      String content = (String) resultDoc.getFieldValue("content");
      String id = (String) resultDoc.getFieldValue("id"); //id is the uniqueKey field
      String subject = (String) resultDoc.getFieldValue("subject");
      categories = (ArrayList) resultDoc.getFieldValue("categories");
      System.out.println("**************");
      System.out.println("categories is -->>"+categories.toString());
   }
}

More advanced Solr Searches will be described later.

Comments are welcome.

Enter your email address:

Delivered by FeedBurner

Concepts in JBoss Drools


Business rule is any real world knowledge or exception that can be explained in when this happens do this.

These rules should be explained in as simple as possible in expressive language.

Business Systems generally do the following things –

  • Take information via User Interface.
  • Process these information with pre-exsiting knowledge.
  • Store the information in any format for further processing(like analytics etc.)

In these three layers of works the middle one is most variable in nature and the knowledge growth here is ever-growing.

This layer known as business layer is the most input centric layer in common business pratices. And it requires upgradation for each iteration in complex business world.

All the layers, as explained, are coupled in application and it is the most challanging part to de-couple those layers.

The Problem :

Generally Business logics are crafted in code and for every logic changes the code change is required which is difficult to maintain for each veersion and audit them. Also the domain knowledge experts and the application software exprts talk and work in different mode.

So the updation of business logic and implementation of these logics are having undesirable effects in organisation.

The Solution :

And here the requirement of rule engine comes.

In a rule engine we can evaluate the rules before implementing them in production nd can be verified by domain experts.

Here we can expressively declare “the things to do.” And so we can focus on the domain and separately work with rule verification and the presentation and repository layer coding can be developed separately with the help of tech guys for the application development.

As the rules are developed differently, the rules are more dynamic and scalable in nature through rule engine. The development and change management in rules can be parallel done with the change of infrastructure code.

Also the rules and implementation of the rules can be easily verified by domain experts before production – which can be termed as business logic audit.

In JBoss, the implementation of the rule engine is done through BRMS (Guvnor).

BRMS can be opened and the rules can be edited in any standard web browser.

It has –

1> Standard Web based rule editor (Guided).
2> Helpful wizards to develop the rules.
3> Team editing
4> Version management of rules and related assets
5> Rules Compiler
6> Fact Model (Assets)
7> Deployment mechanism
8> Import and export of data

Most helpful information about JBoss Drools can be found here.

An example of Drool based application is explained here.

Try to evaluate the rule engine to have ease in the application software development world.

Comments and suggestions are welcome.

Enter your email address:

Delivered by FeedBurner

B8FGNJ3HZVC3

Liferay Tables – A brief Description – will be filled up as we experience further


Table Name Description
account_ Main Account Information is stored here.
address Nothing comes default
announcementsdelivery
announcementsentry
announcementsflag
assetcategory all the categrories are stored here, which are entered from Liferay Admin Panel
assetcategoryproperty Properties for the Asset Category are saved in Key-Value Pair.
assetentries_assetcategories
assetentries_assettags
assetentry
assetlink
assettag Tagging of Assests – WCM Journal Articles are saved here.
assettagproperty
assettagstats For how many assets, a particular tag is associated.
assetvocabulary Main Vocabulary for Assets are saved here. It is a classification of Assets.
blogsentry
blogsstatsuser
bookmarksentry
bookmarksfolder
browsertracker
calevent
chat_entry Chat content within two chat users are saved here.
chat_status
classname_
clustergroup
company Main company information is saved here.
contact_ User Contact Information is saved here.
counter For all the dao objects in liferay, the primary key counters are saved here.
country All the Country Information
cyrususer
cyrusvirtual
dlfileentry
dlfilerank
dlfileshortcut
dlfileversion
dlfolder
emailaddress
expandocolumn
expandorow
expandotable
expandovalue
groups_orgs
groups_permissions
groups_roles
groups_usergroups
group_ User Goup Information is saved here.
ics_m_applicationorganization
ics_m_city
ics_m_corporate
ics_m_degreebranch
ics_m_educationaldegree
ics_m_educationallevel
ics_m_eventtype
ics_m_institutelist
ics_m_institutetype
ics_m_membershiplevel
ics_m_region
ics_m_selectionprocedure
ics_m_state
ics_m_statusmst
ics_m_student
ics_m_zip
ics_td_campusselectionproceduredtls
ics_td_jobeducation
ics_td_jobsalary
ics_td_requirementdetails
ics_td_rpireqinstitute
ics_td_rpirequirement
ics_td_totalcampusprocessperiod
ics_th_event
ics_th_rpi
ics_t_workorderdetails
igfolder image folder information is stored here
igimage image entry is stored here.
image image property is stored here.
journalarticle Main Web Contents are stored in this table
journalarticleimage
journalarticleresource Group and Article Resource Association is stored here.
journalcontentsearch
journalfeed
journalstructure
journaltemplate
layout Layout Definitions are stored here.
layoutprototype
layoutset Theme to Layout Association is saved here.
layoutsetprototype
listtype
lock_
mbban
mbcategory
mbdiscussion
mbmailinglist
mbmessage
mbmessageflag
mbstatsuser
mbthread
membershiprequest
organization_
orggrouppermission
orggrouprole
orglabor
passwordpolicy
passwordpolicyrel
passwordtracker
permission_
phone
pluginsetting
pollschoice
pollsquestion
pollsvote
portlet Portlet to Company Assocation is saved here.
portletitem
portletpreferences Portlet Name and all the preferences are saved here.
quartz_blob_triggers
quartz_calendars
quartz_cron_triggers
quartz_fired_triggers
quartz_job_details
quartz_job_listeners
quartz_locks
quartz_paused_trigger_grps
quartz_scheduler_state
quartz_simple_triggers
quartz_triggers
quartz_trigger_listeners
ratingsentry
ratingsstats
region Regions under Country
release_
resourceaction
resourcecode
resourcepermission
resource_
roles_permissions User Role to Permission Relation
role_ User Role Definition
scframeworkversion
scframeworkversi_scproductvers
sclicense
sclicenses_scproductentries
scproductentry
scproductscreenshot
scproductversion
servicecomponent
shard
shoppingcart
shoppingcategory
shoppingcoupon
shoppingitem
shoppingitemfield
shoppingitemprice
shoppingorder
shoppingorderitem
socialactivity
socialequityassetentry
socialequitygroupsetting
socialequityhistory
socialequitylog
socialequitysetting
socialequityuser
socialrelation
socialrequest
subscription
tasksproposal
tasksreview
team
ticket
usergroup User Gorup Information is saved here.
usergroupgrouprole
usergrouprole
useridmapper
users_groups User to Group Mapping
users_orgs
users_permissions
users_roles User to Role Mapping
users_teams
users_usergroups
usertracker
usertrackerpath
user_ User information is here
vocabulary
webdavprops
website
wikinode
wikipage
wikipageresource
workflowdefinitionlink
workflowinstancelink

Enter your email address:

Delivered by FeedBurner

Be Social, Go Local


Social Media Marketing
Think global act local.

It maybe an old adage in marketing but it is as applicable today as a newly minted coin.

Does social media marketing truly need to go local?

The answer is a very big YES.

For all the very big brands with very big commercial stores, study shows this new year will be all about locality. It will all be about bonding and developing a sense of belonging. So ho hum. Get set and start reaching out to people locally.

The world has sure become social and that very prosocial audience make the majority of any spender today. Thus it is no rocket science that content creators need to be relevant enough to let people identify with them and in the same time be absolutely grounded in the local culture.

So why this topic in a social media marketing blog?

Because we reach the most number of localities and brands might as well accept it. Since the first post was about Content Marketing this one simply makes sure we do not make any mistakes doing just that.

Lets get down to the field.

Localisation is at the heart of any strategy.

Be it a Facebook page for a brand for their fans in Uruguay or the Twitter handle for a brand’s audience in Singapore, the only way you can keep customers loyal is by telling them what is relevant to them.

Here is the social media strategy of Makemytrip right from their head of marketing. Its all about being local.

With the highly effective geo tracking tools available, now identifying and grouping your customers is just a click away. So start grouping your Twitter followers and Facebook fans. Connect with other social brands in that locality to drive maximum awareness of your brand and make it as highly relevant as possible.

Localise a Facebook page but do not forget to unify it under one corporate name. You could always have tabs customised to cater to one particular country.

In fact Facebook gives you the option to display a post only to a certain group of readers.

It’s definitely a good idea to group people according to a locality and target only them. An earthquake in Japan may not take as much precedence in Ukraine. It pays to invest in localising, yet globalising your social media.

Some of the things that need to be kept in mind while structuring a social media strategy in a local market are as follows

  • Language differences
  • Difference in the tradition and culture of a particular place
  • Deliberate differences in messaging / tone of voice
  • Differences in promotional activity, as different news affect places differently
  • Differences in social media platform usage from place to place
  • Is sufficient resource available to maintain more than one presence?

One of the best examples of localised social media marketing is undertaken by makemytrip.com. One of the most successful online portals for travel booking, they sure give a zing to the local flavour and always keep their offers and communication attuned to the local mindset to get the maximum number of engagement in Social media and some very effective feedback from the locality.

Enter your email address:

Delivered by FeedBurner

The Social Influencer


Well, the image above is extremely self explanatory and gives a very good break up of the range of influencers that inhabit the social media.

What really needs to be assessed is how important are they?

With millions of people logging in every second to the social media sites worldwide, it is quite obvious that the trends that they follow is definitely influenced. Today you have awards for the best social media celebrity, simple because the whole aspect of affecting people’s lives has taken a very online turn. Thus it is suffive to say that social media influencers rank extremely high in social ladder.

We may have already classified our influences quite effectively.

What the brand must do is identify them.

It may be the most incongruous geek who have the highest score in a game where you want to advertise to reach the youth or she can be the housewife with a blog about the kichen instances. The main job is to track the online conversations, identify the people who are setting the trends and target.

The next step is to Engage with the identified influencers as people and not as prospects.

The main reason why they are influencers is because they connect with the audience. Now it is your turn to treat them as people with preferences and approach them in helping you out. Always identify influencers who are pro your brand and will advocate it. Give them a product that they will proudly like, tweet, share and blog about. Influencers today are key to your online success.

It is about time marketers figure out some of the keys to online success. One is definitely acknowledging the influencers. They are the sole beings that make digital a credible and believable world. And today they are one of the drivers to your brands online success.

Enter your email address:

Delivered by FeedBurner

Java Jersey – REST based Web Service Example


We are describing a simple REST based web service example with Java jersey.
This project is a Dynamic Web Project in Eclipse and was tested in Tomcat 7.

You can have a view of the Libraries for this Project in below Image –

Java Jersey  Project Structure

We are giving souce code of the Web Service Class and showing a example of Test Code.

The Web Service Skeleton is

 

//Sets the path to base URL + /hello
@Path("/hello")
public class Hello {

  // This method is called if TEXT_PLAIN is request
  @GET
  @Produces(MediaType.TEXT_PLAIN)
  public String sayPlainTextHello() {
    return "Hello Jersey";
  }

  // This method is called if XML is request
  @GET
  @Produces(MediaType.TEXT_XML)
  public String sayXMLHello() {
    return "" + " Hello Jersey" + "";
  }

  // This method is called if HTML is request
  @GET
  @Produces(MediaType.TEXT_HTML)
  public String sayHtmlHello() {
    return " " + ""
        + "

” + “Hello Jersey” + “

" + " ";
  }

} 

The test class is

 

public class Test {
  public static void main(String[] args) {
    ClientConfig config = new DefaultClientConfig();
    Client client = Client.create(config);
    WebResource service = client.resource(getBaseURI());
    // Fluent interfaces
    System.out.println(service.path("rest").path("hello").accept(MediaType.TEXT_PLAIN).get(ClientResponse.class).toString());
    // Get plain text
    System.out.println(service.path("rest").path("hello").accept(MediaType.TEXT_PLAIN).get(String.class));
    // Get XML
    System.out.println(service.path("rest").path("hello").accept(MediaType.TEXT_XML).get(String.class));
    // The HTML
    System.out.println(service.path("rest").path("hello").accept(MediaType.TEXT_HTML).get(String.class));

  }

  private static URI getBaseURI() {
    return UriBuilder.fromUri("http://localhost:8081/BrandServer").build();
  }

} 

Source code is here.

This is a starting point for REST based web service in Java. Rest of the things can be built in Business Logic.

Update 23/02/2013
=================

One important part I have missed in this source code is, attaching the web.xml for this example. I have attached the web.xml here. This was pointed out by one of commenter to whom we are grateful.

Enter your email address:

Delivered by FeedBurner

JBoss Drool based Project – an Example


I have previously written JBoss Drools – an Initial Study.

Now as I thought of showing an example of drool project, I am directing showing coding related to this.

As I thought, the related libraries are necessary for the project, I am showing the image for this in a Dynamic Web Project in eclipse.

Please take all the jars as specified in the project.

Now for example working purpose I have created one servlet which actually validate the orders via drool file.

The drool file is –

So pass and fail rule is created here.

After this, I am showing the codebase related to Drool Validation code in Servlet –

I have placed drools related configuration in an other file – Droolsinitialiser.java and used stateless drool object –

So these codes are self-explanatory. For any better help, I am attaching the source files with the eclipse project for DroolWebProject. For space crunch, the library jars are not included here.

This project can be tested in Tomcat 7.

After rule change in .drl file, we need no new deployment, but re-staring of tomcat to take the effect of rule change.

This is an drool infrastructure ready codebase to start with drools. Any comments and suggestions related to Drool rules related project are welcome.

7AQT8TGWTJRA

Enter your email address:

Delivered by FeedBurner

Jericho HTML Parser – Simple way of HTML Parsing


We had chance to extract the HTML and get the cleared text as input of further data processing. Here we have used jericho html parser. Parsing with this open source library was very useful in our previous projects. So I am giving a code base straight for the ease of work.
Some lines here are documented and others are self explanatory.

 

import net.htmlparser.jericho.*;

public class ExtractText {

static String htmlText = "Put your html code here for testing...";

	public static void main(String[] args) throws Exception {
		Source source=new Source(htmlText);

		// Call fullSequentialParse manually as most of the source will be parsed.
		source.fullSequentialParse();

		System.out.println("\nAll text from file (exluding content inside SCRIPT and STYLE elements):\n");
		System.out.println(source.getTextExtractor().setIncludeAttributes(true).toString());

  }

	private static String getTitle(Source source) {
		Element titleElement=source.getFirstElement(HTMLElementName.TITLE);
		if (titleElement==null) return null;
		// TITLE element never contains other tags so just decode it collapsing whitespace:
		return CharacterReference.decodeCollapseWhiteSpace(titleElement.getContent());
	}

	private static String getMetaValue(Source source, String key) {
		for (int pos=0; pos<source.length();) {
			StartTag startTag=source.getNextStartTag(pos,"name",key,false);
			if (startTag==null) return null;
			if (startTag.getName()==HTMLElementName.META)
				return startTag.getAttributeValue("content"); // Attribute values are automatically decoded
			pos=startTag.getEnd();
		}
		return null;
	}
}

Enter your email address:

Delivered by FeedBurner

What is Asterisk?


We have described Asterisk Installation and configuration process in our previous article.

Today we will try to explain Asterisk in a nutshell.

Asterisk is an open source software PBX created by Mark Spencer in the year 1999.

Asterisk   allows attached telephones to make calls to one another and it also can connect different telephone networks like the traditional PSTN and Softphone which uses VOIP.

Asterisk provides Voicemail services with Directory, Call Conferencing, Interactive Voice Response  and Call Queuing. It has support for three-way calling, caller ID services, ADSI, IAX, SIP, H.323 (as both client and gateway), MGCP (call manager only) and SCCP/Skinny.

Asterisk was originally designed for Linux but also runs on a variety of other operating systems including FreeBSD, Mac OS X, OpenBSD & Microsoft Windows also (though not recommended). Asterisk needs no additional hardware for Voice over IP. For interconnection with digital and analog telephony equipment, Asterisk supports a number of hardware devices, most notably all of the hardware manufactured by Asterisk’s sponsors, Digium. For interconnection with the cellular network (GSM or CDMA), Asterisk can use the Celliax channel driver or chan_mobile that is in the trunk now and there is also a unofficial back ported version.

The beauty of Asterisk is that it provides all the features that we expect from a proprietary PBX & many more and you can enjoy the power of Asterisk for free. You can configure Asterisk to meet your needs.

Asterisk is configured by a set of configuration text files. One of these, extensions.conf, contains the operational flow logic of Asterisk. A native scripting language is used to define the elements of process control, namely variables, procedural macros, contexts, extensions, and actions. A context groups the valid destination codes which apply to a set of channels on which calls can be presented. These numbering codes, called extensions, are the starting points for the programming steps that process calls.

Enter your email address:

Delivered by FeedBurner

JBoss Drools – an Initial Study


As we have faced ever-changing business rules environment of organisations, we were in search of some sort of code base, by which we can atleast resist the every week deployment scenario of Application in Organisations.

So, here we have found JBoss Drools – an rule engine offered by Jboss.

Well structured Java web/enterprise applications are mainly separated into

1> Front-end layer,

2>Service and business logic layer

3> Data Access layer

By using RAD tools, we can build dao code automatically, with proper database designed.

One of such framework is Spring Roo.

Also for structured web framework, there is struts, spring mvc or Google Web Toolkit and such other good farmeworks.

To fight with every-day changing business logic, a standard framework was much needed, which can be handled without deploying the actual code base.

So here JBoss Drools comes with rule engine.

Definition of Rule Engine –

A rule engine is a way to handle any situation with “what to do” approach to solve a diverse set of problems with Data with the defined rules as set in the framework, which actually drive the automation of business rules.

What we can do with Rule Engine –

  • Separate the DAO objects from Business Rules to minimise the deployment issues and put the rules in the system dynamically to validate the data set to be stored in the application.
  • Use of knowledge from Business Rule Implementation experts and let them handle the rule without touching the actual enterprise system architecture.
  • Use of rules as much as readable by general users i.e. not only core technology guy can use it – all the main stakeholders of the application can use and extend it and use this as further evidence of present business logic.

Usually Jboss drools files are written in .drl files.

These files consists of set of rules.

The dataset, which is passed through the service and business logic layer, are validated against the set of rules in the .drl files.

An example rule we might consider is –

“We will buy the car if we get a $30000 loan”

So the rule will be in JBoss Drool Language –

rule “BuyCar”
when
carLoan:CarLoan (amount<30000)
then
System.out.println(“Can’t afford the Car”);
end

So this is a very basic introduction or JBoss Drools.

I will cover –

Advance concepts about Drools rule engine.

Case Study of Drools Framework in practical application.

So, This is my first post regarding JBoss Drools.

Comments regarding Drools are welcome.

Enter your email address:

Delivered by FeedBurner