Solr schema.xml stroed/indexed

When defining fields in Solr schema.xml we can define whether we should be able to only search, show or both search and show data in the fields.
Setting the attribute stored=true means that the field will be shown in the search result. Indexed=true means we can search the field.

Sometimes we want to display data in the search result, but it’s not necessary to be able to search the field. This can be accomplished by setting the field attributes to
[xml]
stored=true indexed=false
[/xml]

How to delete Solr index

Your index is stored in \Solr\core\data
Eg. \Solr\collection1\data

If you delete the data folder or underlying folders “index” and “tlog”, it will delete your index.

Delete Solr index data

A nicer way of achieving this, is by running the following HTTP command

[code]http://localhost:8983/solr/collection1/update?stream.body=<delete><query>*:*</query></delete>[/code]

Password protect Solr admin

Solr HTTP admin interface is per default unprotected and can be accessed by everyone.
To secure the interface with HTTP web authentication follow these steps.

Open:
[shell]C:\Tomcat\webapps\solr\WEB-INF\web.xml[/shell]

After:
[xml]<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5"
metadata-complete="true">[/xml]

Insert:
[xml]<security-constraint>
<web-resource-collection>
<web-resource-name>
Solr Lockdown
</web-resource-name>
<url-pattern>/</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>solr_admin</role-name>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>Solr</realm-name>
</login-config>
<security-role>
<description>solr users</description>
</security-role>[/xml]

Open:
[shell]C:\Tomcat\conf\tomcat-users.xml[/shell]

Inside [xml]<tomcat-users> </tomcat-users>[/xml] insert:
[xml]<user name="myUsername" password="myPassword" roles="admin-gui,manager-gui,solr_admin"></user>[/xml]

SimplePropertiesWriter Unable to read: dataimport.properties

After setting Solr DataImportHandler up and trying to fetch data from SQL Server via the HTTP API (http://localhost:8080/solr/dataimport?command=full-import) I got an error response back, telling all changes had been rolled back.

[code]
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">7</int>
</lst>
<lst name="initArgs">
</lst><lst name="defaults">
<str name="config">data-config.xml</str>
</lst>

<str name="command">full-import</str>
<str name="status">idle</str>
<str name="importResponse"></str>
<lst name="statusMessages">
<str name="Time Elapsed">0:1:19.495</str>
<str name="Total Requests made to DataSource">1</str>
<str name="Total Rows Fetched">0</str>
<str name="Total Documents Processed">0</str>
<str name="Total Documents Skipped">0</str>
<str name="Full Dump Started">2013-08-14 11:20:59</str>
<str name="">Indexing failed. Rolled back all changes.</str>
<str name="Rolledback">2013-08-14 11:21:28</str>
</lst>
<str name="WARNING">
This response format is experimental. It is likely to change in the future.
</str>
</response>
[/code]

The Catalina log didn’t tell me anything useful, but checking “Logging” in http://localhost:8080/solr/ threw:
[code]
WARN SimplePropertiesWriter Unable to read: dataimport.properties
[/code]

It simply says that Solr is unable to read the file dataimport.properties.
The file is not a part of the standard Solr package and is not created automatically.
To fix this warning, simply created an empty file called “dataimport.properties” in your Solr conf directory, eg. /Solr/collection1/conf/ and make sure Apache has write access to it.

Can’t find (or read) directory to add to classloader

Getting these error messages in Apache Solr administration interface when you tab logging?
Well, it’s most likely because you are using the example solrconfig.xml located in \Solr\Collection1\conf\solrconfig.xml.

Simply modify or out comment the following lines:
[code]
<lib dir="../../../contrib/extraction/lib" regex=".*\.jar"></lib>
<lib dir="../../../dist/" regex="solr-cell-\d.*\.jar"></lib>

<lib dir="../../../contrib/clustering/lib/" regex=".*\.jar"></lib>
<lib dir="../../../dist/" regex="solr-clustering-\d.*\.jar"></lib>

<lib dir="../../../contrib/langid/lib/" regex=".*\.jar"></lib>
<lib dir="../../../dist/" regex="solr-langid-\d.*\.jar"></lib>

<lib dir="../../../contrib/velocity/lib" regex=".*\.jar"></lib>
<lib dir="../../../dist/" regex="solr-velocity-\d.*\.jar"></lib>
[/code]

You can find a issue ticket about this problem at Solr issue tracker.

12:57:57WARNSolrResourceLoaderCan’t find (or read) directory to add to classloader: ../../../contrib/extraction/lib (resolved as: C:\Solr\collection1\..\..\..\contrib\extraction\lib).
12:57:57WARNSolrResourceLoaderCan’t find (or read) directory to add to classloader: ../../../dist/ (resolved as: C:\Solr\collection1\..\..\..\dist).
12:57:57WARNSolrResourceLoaderCan’t find (or read) directory to add to classloader: ../../../contrib/clustering/lib/ (resolved as: C:\Solr\collection1\..\..\..\contrib\clustering\lib).
12:57:57WARNSolrResourceLoaderCan’t find (or read) directory to add to classloader: ../../../dist/ (resolved as: C:\Solr\collection1\..\..\..\dist).
12:57:57WARNSolrResourceLoaderCan’t find (or read) directory to add to classloader: ../../../contrib/langid/lib/ (resolved as: C:\Solr\collection1\..\..\..\contrib\langid\lib).
12:57:57WARNSolrResourceLoaderCan’t find (or read) directory to add to classloader: ../../../dist/ (resolved as: C:\Solr\collection1\..\..\..\dist).
12:57:57WARNSolrResourceLoaderCan’t find (or read) directory to add to classloader: ../../../contrib/velocity/lib (resolved as: C:\Solr\collection1\..\..\..\contrib\velocity\lib).
12:57:57WARNSolrResourceLoaderCan’t find (or read) directory to add to classloader: ../../../dist/ (resolved as: C:\Solr\collection1\..\..\..\dist).

Install Solr under Windows

Install Solr under Windows

Installing and getting Solr up and running is straight forward, as long as you follow these simple steps. I ran into problems myself trying to get Solr starting up under Tomcat, even after reading several posts explaining how to, which is why I wrote this post, explaining all the necessary steps. Feel free to make a comment, if you have any questions or run into problems.

1. Download Apache Tomcat from Apache Software Foundation. I downloaded and installed Tomcat 7.0.42 “32-bit/64-bit Windows Service Installer” under the location c:\Tomcat\

2. Download the latest version of “Solr”. I downloaded Solr 4.4.0.
– Open solr-4.4.0.zip, navigate to \example\solr and extract the directories and files to c:\solr\, so it contains; bin, collection1, README.txt, solr.xml and zoo.cfg

– Again in solr-4.4.0.zip navigate to \example\lib and extract all the jar-files into c:\Tomcat\lib\. Repeat the same procedure with the jar-files in \examples\lib\ext.

– In solr-4.4.0.zip navigate to \example\webapps and extract solr.war to c:\Tomcat\webapps\. If the file is called solr-versionNumber.war, rename it to solr.war

3. In C:\Tomcat\conf\Catalina\localhost create a file called “solr.xml” with following content, where you specify Solr docBase “c:/Tomcat/webapps/solr.war” and enviroment value “/Tomcat/webapps/”.

[xml]
<?xml version="1.0" encoding="UTF-8"?>
<context docBase="c:/Tomcat/webapps/solr.war" debug="0" crossContext="true" >
<environment name="solr/home" type="java.lang.String" value="/Tomcat/webapps/" override="true"></environment>
</context>
[/xml]

4. Open up C:\Tomcat\webapps\solr\WEB-INF\web.xml and uncomment the following and replace “/put/your/solr/home/here” with your solr location

[xml]
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>C:\Solr</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
[/xml]

During these steps you might have to stop and start your Apache Tomcat to be able to write to the files and reload the changes. To stop/start Apache Tomcat, click the Apache icon in the task bar and click “Stop service / Start service”.

Restart Apache Tomcat Windows

You should now be able to navigate to http://localhost:8080/solr/ and get the Solr admin site, presuming you installed Apache Tomcat on port 8080 (as per default)

Solr 4.4.0 admin page

If you run into problems, you can view the Catalina log located in c:\Tomcat\logs\catalina.date.log.