Saturday, 10 September 2016

How to place http authentication in SOLR?

Tested with SOLR version is 4.4
Place the following code in example\etc\webdefault.xml file under <web-app>
<web-resource-name>Solr authenticated application</web-resource-name>

<realm-name>Test Realm</realm-name>

Brief description of above parameters:
url-pattern refers to the url for which this authentication required, since, mentioned as "/*", authentication would be required for any url. Once after authentication happens, application won't ask the authentication until browser session gets destroyed.
role-name refers to the role that access exists. Similarly, we can place separate access for each functionality like search, update, delete etc
realm-name refers to the name used to display while asking for authentication, this should match with the name under set parameters of example\etc\jetty.xml file as follows:

Place the following code under <configure>
<Call name="addBean">
<New class="">
<Set name="name">Test Realm</Set>
<Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/</Set>
<Set name="refreshInterval">0</Set>
Now, create / update the file in etc folder with authentication details as follows:
<username>: <password>, <role>
Eg: user: pwd, admin
So, we can give multiple users with multiple roles and provide access on role basis.

For more information, please refer
If needed to configure realm for TOMCAT, please use UserDatabaseRealm as explained in

How to create multiple indexes in SOLR?

For multiple Indexes, either we need to use multiple SOLRs in different ports or collections/cores.

Multiple SOLR ports can be achieved as follows, we need to have multiple copies of example folder with different port number, port number can be updated in jetty.xml file under example\etc folder. So, we can access two instances separately as http://localhost:8080/solr/#/ (port number : 8080) and http://localhost:8983/solr/#/ (port number : 8983).
For multicore, we have a folder named "multicore" inside example folder. We can see core0 and core1 folders by default. These folders will have separate schema and solrconfig files. Similarly, we have have multiple cores here. The multicore folder will have a solr.xml file. Need to mention each core in this file under <cores> as follows:

<core name="core0" instanceDir="core0" />
<core name="core1" instanceDir="core1" />
<core name="core2" instanceDir="core2" />

Here, instanceDir refers to the folder name and name refers to the path. Now, need to mention the solr home while starting the solr to make multicore as home. The command is as follows:

java -Dsolr.solr.home=multicore -jar start.jar

For multiple collections, create collections(copy the existing and paste) under example\solr with changing the file, need to mention the current collection name in file (update the file to text format, place the value, update the file format to txt).

Now, we can start solr without mentioning the solr home, command is java -jar start.jar

How to delete duplicate records from a table in MYSQL ?

Table Name : records
Procedure 1 :
Step 1 :
Create new table by removing duplicates
CREATE TABLE uniquerecords AS SELECT * FROM records GROUP BY name HAVING ( COUNT(name)>0 )
Step 2 :
Delete old table
DROP TABLE records
Step 3 :
Rename the New Table to Old Table
RENAME TABLE uniquerecords TO records
Procedure 2 : (IF Ajay is repeated five times, the below query would delete Ajay four times.)

DELETE FROM records USING records, records AS virtualtable WHERE (records.sno>virtualtable.sno) AND (
This would delete all the records except the first one.
Procedure 3 : (IF Ajay is repeated five times, the below query would delete all the five records.)

DELETE FROM records USING records, records AS virtualtable WHERE (records.sno=virtualtable.sno) AND (

How to get first 5 records from a table without using LIMIT in MYSQL ?

Table Name: records
Here, we have 10 records in the table, however, we need to retreive 5 records without using LIMIT keyword.
Query :
 SELECT limitrecordsone.sno, FROM records limitrecordsone WHERE (SELECT COUNT(*) FROM records limitrecordstwo WHERE limitrecordstwo.sno <= limitrecordsone.sno) <=5

Get Player Name and Coach Name from a single table in MYSQL ?

Table Name: playercoach
Player Coach Table
Here, the number in the column coach represents the sno of the coach.
Procedure 1:
SELECT player.sno,,(SELECT FROM playercoach coach WHERE AS coachname FROM playercoach player
Procedure 2:
SELECT player.sno,, AS coachname FROM playercoach player JOIN playercoach coach ON
Procedure 1 would be better in the sense of performance.

How to find ID of a new row added to a table or what is the usage of mysql_insert_id() ?

mysql_insert_id() function is useful to get the ID generated in the last query.
$query=mysql_query("INSERT into testtable VALUES('testvalue')");
$rowid = mysql_inser_id();
$rowid contains the new row id.

What are the different types of Errors in PHP?

Types of error
Basically there are four types of errors in PHP, which are as follows:
  • Parse Error (Syntax Error)
  • Fatal Error
  • Warning Error
  • Notice Error
Please use error_reporting(E_ALL); to get display all types of errors.
1. Parse Errors (syntax errors)
The parse error occurs if there is a syntax mistake in the script; the output is Parse errors. A parse error stops the execution of the script. There are many reasons for the occurrence of parse errors in PHP. The common reasons for parse errors are as follows:
Common reason of syntax errors are:
  • Unclosed quotes
  • Missing or Extra parentheses
  • Unclosed braces 
  • Missing semicolon

echo "Champion";
echo "Dusk"
echo "Light";
In the above code we missed the semicolon in the second line. When that happens there will be a parse or syntax error which stops execution of the script, as follows:
Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in C:\dev\apache\apache2.2.8\htdocs\testing.php on line 3

2. Fatal Errors
Fatal errors are caused when you're asking PHP to do, that can't be done. Fatal errors stop the execution of the script. If you are trying to access the undefined functions, then the output is a fatal error.
echo "Fatal Error !!";
In the above code we called function fun2 which is not defined. So a fatal error will be produced that stops the execution of the script. Like as follows:
Fatal error: Call to undefined function fun2() in C:\dev\apache\apache2.2.8\htdocs\testing.php on line 2

3. Warning Errors
Warning errors will not stop execution of the script. The main reason for warning errors are to include a missing file or using the incorrect number of parameters in a function.

include ("Welcome.php");
echo "You got Warning Error!!";
In the above code we include a welcome.php file, however the welcome.php file does not exist in the directory. So there will be a warning error produced but that does not stop the execution of the script i.e. you will see a message Warning Error !!. Like as follows:
Warning: include(Welcome.php) [function.include]: failed to open stream: No such file or directory in C:\dev\apache\apache2.2.8\htdocs\testing.php on line 2

Warning: include() [function.include]: Failed opening 'Welcome.php' for inclusion (include_path='.;C:\php5\pear') in C:\dev\apache\apache2.2.8\htdocs\testing.php on line 2
You got Warning Error!! 

4. Notice Errors
Notice that an error is the same as a warning error i.e. in the notice error execution of the script does not stop. Notice that the error occurs when you try to access the undefined variable, then produce a notice error.

echo $test;
echo "You got Notice error!";


In the above code we tried to print a variable which named $test, which is not defined. So there will be a notice error produced but execution of the script does not stop, you will see a message  "You got Notice error!". Like as follows:
Notice: Undefined variable: test in C:\dev\apache\apache2.2.8\htdocs\testing.php on line 2
You got Notice error!