lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve Rowe (Confluence)" <>
Subject [CONF] Apache Solr Reference Guide > Running Solr
Date Wed, 24 Jul 2013 23:33:00 GMT
Space: Apache Solr Reference Guide (
Page: Running Solr (

Change Comment:
Remove unnecessary quotes around code box title

Edited by Steve Rowe:
This section describes how to run Solr with an example schema, how to add documents, and how
to run queries.

h2. Start the Server

If you didn't start Solr after installing it, you can start it by running {{start.jar}} from
the Solr {{example}} directory.

$ java -jar start.jar

If you are running Windows, you can start the Web server by running {{start.bat}} instead.

C:\Applications\Solr\example > start.bat

That's it\! Solr is running. If you need convincing, use a Web browser to see the Admin Console.


_The Solr Admin interface._

If Solr is not running, your browser will complain that it cannot connect to the server. Check
your port number and try again.

h2. Add Documents

Solr is built to find documents that match queries. Solr's schema provides an idea of how
content is structured (more on the schema [later|solr:Documents, Fields, and Schema Design]),
but without documents there is nothing to find.  Solr needs input before it can do anything.

You may want to add a few sample documents before trying to index your own content.  The Solr
installation comes with example documents located in the {{example/exampledocs}} directory
of your installation.

In the {{exampledocs}} directory is the SimplePostTool, a Java-based command line tool, {{post.jar}},
which can be used to index the documents. Do not worry too much about the details for now.
The [Indexing and Basic Data Operations] section has all the details on indexing.

To see some information about the usage of {{post.jar}}, use the {{\-help}} option.

$ java -jar post.jar -help

The SimplePostTool is a simple command line tool for POSTing raw XML to a Solr port. XML data
can be read from files specified as command line arguments, as raw command line {{arg}} strings,
or via STDIN.


java -Ddata=files -jar post.jar *.xml
java -Ddata=args  -jar post.jar '<delete><id>42</id></delete>'
java -Ddata=stdin -jar post.jar < hd.xml

Other options controlled by System Properties include the Solr URL to POST to, and whether
a commit should be executed. These are the defaults for all System Properties:


Go ahead and add all the documents in the directory as follows:

$ java -Durl=http://localhost:8983/solr/update -jar post.jar *.xml
SimplePostTool: version 1.2
SimplePostTool: WARNING: Make sure your XML documents are encoded in UTF-8, other encodings
are not currently supported
SimplePostTool: POSTing files to
SimplePostTool: POSTing file hd.xml
SimplePostTool: POSTing file ipod_other.xml
SimplePostTool: POSTing file ipod_video.xml
SimplePostTool: POSTing file mem.xml
SimplePostTool: POSTing file monitor.xml
SimplePostTool: POSTing file monitor2.xml
SimplePostTool: POSTing file mp500.xml
SimplePostTool: POSTing file sd500.xml
SimplePostTool: POSTing file solr.xml
SimplePostTool: POSTing file spellchecker.xml
SimplePostTool: POSTing file utf8-example.xml
SimplePostTool: POSTing file vidcard.xml
SimplePostTool: COMMITting Solr index changes..
Time spent: 0:00:00.633

That's it\! Solr has indexed the documents contained in the files.

h2. Ask Questions

Now that you have indexed documents, you can perform queries. The simplest way is by building
a URL that includes the query parameters. This is exactly the same as building any other HTTP

For example, the following query searches all document fields for "video":


Notice how the URL includes the host name ({{localhost}}), the port number where the server
is listening ({{8983}}), the application name ({{solr}}), the request handler for queries
({{select}}), and finally, the query itself ({{q=video}}).

The results are contained in an XML document, which you can examine directly by clicking on
the link above. The document contains two parts. The first part is the {{responseHeader}},
which contains information about the response itself. The main part of the reply is in the
result tag, which contains one or more doc tags, each of which contains fields from documents
that match the query. You can use standard XML transformation techniques to mold Solr's results
into a form that is suitable for displaying to users. Alternatively, Solr can output the results
in JSON, PHP, Ruby and even user-defined formats.

Just in case you are not running Solr as you read, the following screen shot shows the result
of a query (the next example, actually) as viewed in Mozilla Firefox. The top-level response
contains a {{lst}} named {{responseHeader}} and a result named response. Inside result, you
can see the three docs that represent the search results.

_An XML response to a query._

Once you have mastered the basic idea of a query, it is easy to add enhancements to explore
the query syntax. This one is the same as before but the results only contain the ID, name,
and price for each returned document. If you don't specify which fields you want, all of them
are returned.


Here is another example which searches for "black" in the {{name}} field only. If you do not
tell Solr which field to search, it will search default fields, as specified in the schema.


You can provide ranges for fields. The following query finds every document whose price is
between $0 and $400.


[Faceted browsing|solr:Faceting] is one of Solr's key features. It allows users to narrow
search results in ways that are meaningful to your application. For example, a shopping site
could provide facets to narrow search results by manufacturer or price.

Faceting information is returned as a third part of Solr's query response. To get a taste
of this power, take a look at the following query. It adds {{facet=true}} and {{facet.field=cat}}.


In addition to the familiar {{responseHeader}} and response from Solr, a {{facet_counts}}
element is also present. Here is a view with the {{responseHeader}} and response collapsed
so you can see the faceting information clearly.

{code:title=An XML Response with faceting|language=xml|borderStyle=solid|borderColor=#666666}
<?xml version="1.0" encoding="UTF-8"?>
<lst name="responseHeader">
<result name="response" numFound="9" start="0">
    <str name="id">SOLR1000</str>
    <str name="name">Solr, the Enterprise Search Server</str>
    <float name="price">0.0</float></doc>
<lst name="facet_counts">
  <lst name="facet_queries"/>
  <lst name="facet_fields">
    <lst name="cat">
      <int name="electronics">6</int>
      <int name="memory">3</int>
      <int name="search">2</int>
      <int name="software">2</int>
      <int name="camera">1</int>
      <int name="copier">1</int>
      <int name="multifunction printer">1</int>
      <int name="music">1</int>
      <int name="printer">1</int>
      <int name="scanner">1</int>
      <int name="connector">0</int>
      <int name="currency">0</int>
      <int name="graphics card">0</int>
      <int name="hard drive">0</int>
      <int name="monitor">0</int>
  <lst name="facet_dates"/>
  <lst name="facet_ranges"/>

The facet information shows how many of the query results have each possible value of the
{{cat}} field. You could easily use this information to provide users with a quick way to
narrow their query results. You can filter results by adding one or more filter queries to
the Solr request. Here is a request further constraining the request to documents with a category
of "software".



Stop watching space:
Change email notification preferences:


View raw message