Monday, 1 September 2014

Some concepts of Solr

Q. Difference in simple query parser and Dismax and eDismax query parser
A: Dismax is an abbreviation of Disjoint Max and it is a popular query mode with Solr. Default query parse in Solr is quite stupid, it doesn't support the syntactic parsing of the query and doesn't handles the exceptions smoothly. If you put some extra character, it might throw exception. Where as Dismax query parse is pretty safe with not to get exceptions, more over it understand the query with logical operator, weight allocation and results accordingly. Like ( "Caner" AND "Blood" ) OR "Blood Cancer"^2 : will be processed by Dismax.

The Extended DisMax Query Parser (eDisMax) is a robust parser designed to process advanced user input directly. It searches for the query words across multiple fields with different boosts, based on the significance of each field. Additional options let you influence the score based on rules specific to each use case (independent of user input).

Q. Using Token based searching in Solr
A. It's simple :) You should prepare a corpus of words and phrases and assign different weight to them based on relevance and importance to your domain. Now once you get the search query, use N gram tokenizer to replace the tokens by boosted factor based one their relevance or weight, and use the AND and OR operation wisely.

Example "Blood cancer symptoms", can be converted into "Blood Cancer symptoms"^100 OR ("Blood caner" AND symptom)^10 OR (Blood AND Cancer AND symptom)^5 OR "Blood Cancer"

This query will result you much relevant results than simple query.

Q. Highlighter to highlight the matched keywords
A : First to set the highlighting while making query, it's very simple you just to query.setHightlight(true) and you can also set other parameters.

        query.setHighlight(true);
        query.setParam("hl.fl", highlightingField);
        query.setParam("hl.mergeContiguous","true");
        query.setParam("hl.usePhraseHighlighter","true");
        query.setParam("hl.simple.pre","");
        query.setParam("hl.simple.post","
");        query.setParam("hl.snippets","2");

Now when you get the response, you have to extract the snippets from response. It is normally a Map of highlightings which returns the list of String (which are snippets) by passing the key as identifier field.

 if (response.getHighlighting()!=null
      && response.getHighlighting().get(object.getId().toString()) != null) {
                    List highlightSnippets = response.getHighlighting().get(object.getId().toString()).get(Highlighted_Field_Name);
                    if(highlightSnippets!=null){
                        StringBuilder contentToShow=new StringBuilder();
                        for(String snippet:highlightSnippets){
                            if(contentToShow.length()<170 p="">                                contentToShow.append(snippet).append(" ...");
                            } else {
                                break;
                            }
                        }
                        object.setContentToShow(contentToShow.toString())
                    }                
}

Refer at here http://wiki.apache.org/solr/HighlightingParameters

Monday, 9 June 2014

Enabling JMX in Tomcat

Any Java program can be monitored using Jconsole. Jconsole is an user interface which comes by default with any JDK package, you just need to type jconsole on your terminal and it will show you the interface. Jconsole works along with JMX, which has to be enabled in the respective java program or JVM.

How to enable JMX in tomcat?

You to enable these variables while starting of the JVM. In tomcat you can simple enable them by using CATALINA_OPTS variable in setenv.sh file in bin folder of tomcat.

-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.port={port to access} 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname={optional, allow what ip to access this Tomcat}
export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname="

To know more details about variables, you can check here,
http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html

After changing this, start the tomcat and then run jconsole from anywhere and connect using
"IP:port", if authentication is enable, enter the credentials also. Now you can see all the JVM stuff, threads, memory usages, CPU usages, GCs performed etc.




Friday, 25 April 2014

RSA server certificate CommonName (CN) 'www.domain.com' does NOT match server name

Hi,

I was getting this error on restarting of my Apache,

"I receive the Error: "RSA server certificate CommonName (CN) 'www.domain.com' does NOT match server name"?"

And there was on website which was able to tell me that is something wrong, which is http://www.sslshopper.com/ssl-checker.html

In my case, I had missed an entry of "ServerName" directive in Apache virtual host configuration.

<VirtualHost _default_:443>
        ServerAdmin webmaster@domain.com
        ServerName www.domain.com

SSLEngine on
SSLCertificateFile /root/ssl/domain.crt
SSLCertificateKeyFile /root/ssl/server.key
SSLCertificateChainFile /root/ssl/bundle.crt

</VirtualHost>

So after entering the ServerName, apache error.log file stopped showing the error message. And the website sslshopper also, started getting the certificate of diagnosis, which made me believe, that issue is resolved.

In general, you should also check
1. DNS entry (host name and IP is correct)
2. /etc/hosts file
3. while creating CSR file, did you miss the common name by any chance, In this case create a new CSR and Re-key the certificate and deploy new certificates.
4. Check in Apache or Nginx, ServerName must match, certificates are issued for a fix domain.




Tuesday, 25 February 2014

fb:share_button/fb:login_button/fb: failed to resize in 45s

I saw one strange issue while using fb_share button which I would like to share and How did I fix it.

When you use fb_share buttons with their stats, means you are using some javascript to get the starts and show beside of the button. When the page load it was working fine, but when you navigate to any other page by clicking on a link or button, and you do browser back to the same page again, it tries to load fb_share button again.. but it keep the textarea locked for 45 seconds, which was quite strange.

I guess it had to be with while fb tries to get the data it also tries to make the proper UI of the button, size and all, and during that period, it locks the textarea.

I started searching for the issue and got a pathetic solution on stackoverflow which says to use this css

.fb-share-button span,
.fb-share-button iframe {
    width: 120px! important;
    height: 25px! important;
}

And amazing part is, it works :)