Return-Path: X-Original-To: apmail-lucene-commits-archive@www.apache.org Delivered-To: apmail-lucene-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6F90910B9D for ; Wed, 24 Jul 2013 23:33:00 +0000 (UTC) Received: (qmail 30264 invoked by uid 500); 24 Jul 2013 23:33:00 -0000 Mailing-List: contact commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list commits@lucene.apache.org Received: (qmail 30227 invoked by uid 99); 24 Jul 2013 23:33:00 -0000 Received: from cwiki-vm.apache.org (HELO cwiki-vm) (140.211.11.69) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 24 Jul 2013 23:33:00 +0000 Received: from cwiki-vm (localhost [127.0.0.1]) by cwiki-vm (Postfix) with ESMTP id 06FF8A262F for ; Wed, 24 Jul 2013 23:33:00 +0000 (UTC) Date: Wed, 24 Jul 2013 23:33:00 +0000 (UTC) From: "Steve Rowe (Confluence)" To: commits@lucene.apache.org Message-ID: <239444143.10840.1374708780028.JavaMail.confluence@cwiki-vm> Subject: [CONF] Apache Solr Reference Guide > Running Solr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Auto-Submitted: auto-generated Space: Apache Solr Reference Guide (https://cwiki.apache.org/confluence/display/solr) Page: Running Solr (https://cwiki.apache.org/confluence/display/solr/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. {code:language=none|borderStyle=solid|borderColor=#666666} $ java -jar start.jar {code} If you are running Windows, you can start the Web server by running {{start.bat}} instead. {code:language=none|borderStyle=solid|borderColor=#666666} C:\Applications\Solr\example > start.bat {code} That's it\! Solr is running. If you need convincing, use a Web browser to see the Admin Console. {{[http://localhost:8983/solr/admin]}} !dashboard.png|border=1! _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. {code:language=none|borderStyle=solid|borderColor=#666666} $ java -jar post.jar -help {code} 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. Examples: {code:language=none|borderStyle=solid|borderColor=#666666} java -Ddata=files -jar post.jar *.xml java -Ddata=args -jar post.jar '42' java -Ddata=stdin -jar post.jar < hd.xml {code} 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: {code:language=none|borderStyle=solid|borderColor=#666666} -Ddata=files -Durl=http://localhost:8983/solr/update -Dcommit=yes {code} Go ahead and add all the documents in the directory as follows: {code:language=none|borderStyle=solid|borderColor=#666666} $ 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 http://10.211.55.8:8983/solr/update.. 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 $ {code} 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 URL. For example, the following query searches all document fields for "video": {{[http://localhost:8983/solr/select?q=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. !solr34_responseHeader.png|width=600! \\ _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. {{[http://localhost:8983/solr/select?q=video&fl=id,name,price]}} 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. {{[http://localhost:8983/solr/select?q=name:black]}} You can provide ranges for fields. The following query finds every document whose price is between $0 and $400. {{[http://localhost:8983/solr/select?q=price:0%20TO%20400&fl=id,name,price]}} [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}}. {{[http://localhost:8983/solr/select?q=price:0%20TO%20400&fl=id,name,price&facet=true&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} ... SOLR1000 Solr, the Enterprise Search Server 0.0 ... 6 3 2 2 1 1 1 1 1 1 0 0 0 0 0 {code} 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". {{[http://localhost:8983/solr/select?q=price:0%20TO%20400&fl=id,name,price&facet=true&facet.field=cat&fq=cat:software]}} {scrollbar} Stop watching space: https://cwiki.apache.org/confluence/users/removespacenotification.action?spaceKey=solr Change email notification preferences: https://cwiki.apache.org/confluence/users/editmyemailsettings.action