SearchHandler is the class name of a Request Handler that responds to search requests. A SearchHandler is usually registered in solrconfig.xml with the name "/select", and with a variety of other names for demonstration purposes.

NOTE: Prior Solr1.3, SearchHandler was named StandardRequestHandler. StandardRequestHandler is now a simple subclass of SearchHandler

Search Components

All of the logic that drives the SearchHandler comes from SearchComponents. If no components are explicitly declared in the request handler config the the defaults are used. They are:

If you want to have a custom list of components (either omitting defaults or adding custom components) you can specify the components for a handler directly:

   <arr name="components">
     <str>query</str>
     <str>facet</str>
     <str>mlt</str>
     <str>highlight</str>
     <str>debug</str>
     <str>someothercomponent</str>
   </arr>

You can add components before or after the main ones like this:

   <arr name="first-components">
     <str>mycomponent</str>
   </arr>

   <arr name="last-components">
     <str>myothercomponent</str>
   </arr>

Note that the any component used (except the defaults) must itself be configured in solrconfig.xml with the name used in the str element as well. See SearchComponent for more details.

Query Params

In addition to the CommonQueryParameters, HighlightingParameters, SimpleFacetParameters, and MoreLikeThis Parameters the Standard Request Handler supports the following Parameters.

q

This is the only mandatory query parameter. It must be a query specified in SolrQuerySyntax, (which has only minor extensions to the Lucene Query Parser Syntax). Examples:

Examples

 

Query String

Meaning

lucene

search for "lucene" in the default field

name:solr

search for "solr" in the "name" field

Note, in solr1.1 the query and sort parameter were combined as a single parameter separated with a ';' (q="name:solr; date desc"). Since solr1.2, it is recommend to use the "sort" parameter described in CommonQueryParameters.

q.op

Specifies the default operator for query expressions, overriding the default operator specified in SchemaXml. Possible values are "AND" or "OR".

df

This parameter overrides the default field defined in SchemaXml, if provided.

Configuration

In addition to specifying components (or first-components and/or last-components) as mentioned above Request Handlers can be configured with three sets of Query Params...

  • defaults - provides default param values that will be used if the param does not have a value specified at request time.
  • appends - provides param values that will be used in addition to any values specified at request time (or as defaults.
  • invariants - provides param values that will be used in spite of any values provided at request time. They are a way of letting the Solr maintainer lock down the options available to Solr clients. Any params values specified here are used regardless of what values may be specified in either the query, the "defaults", or the "appends" params.

Example of Defaults, Appends, and Invariants...

  <requestHandler name="standard" class="solr.StandardRequestHandler">
     <lst name="defaults">
       <!-- assume they want 50 rows unless they tell us otherwise -->
       <int name="rows">50</int>
       <!-- assume they only want popular products unless they provide a different fq -->
       <str name="fq">popularity:[1 TO *]</str>
     </lst>
    <lst name="appends">
      <!-- no matter what other fq are also used, always restrict to only inStock products -->
      <str name="fq">inStock:true</str>
    </lst>
    <lst name="invariants">
      <!-- don't let them turn on faceting -->
      <bool name="facet">false</bool>
    </lst>

  </requestHandler>

Response

By default, the response from the Standard Query Handler contains one <result> block, which is unnamed. If the debugQuery parameter is used, then an additional <lst> block will be returned, using the name "debug". This will contain some useful debugging info, including the original query string, the parsed query string, and explain info for each document in the <result> block. If the explainOther parameter is also used, then additional explain info will be provided for all of documents matching that query.

Sample Responses

These are some examples of what the response might look like for various query URLs...

A simple query that returns one document

http://yourhost.tld:9999/solr/select?q=id:SP2514N&version=2.1&indent=1

<?xml version="1.0" encoding="UTF-8"?>
<response>
<responseHeader><status>0</status><QTime>1</QTime></responseHeader>

<result numFound="1" start="0">
 <doc>
  <arr name="cat"><str>electronics</str><str>hard drive</str></arr>
  <arr name="features"><str>7200RPM, 8MB cache, IDE Ultra ATA-133</str><str>NoiseGuard, SilentSeek technology, Fluid Dynamic Bearing (FDB) motor</str></arr>

  <str name="id">SP2514N</str>
  <bool name="inStock">true</bool>
  <str name="manu">Samsung Electronics Co. Ltd.</str>
  <str name="name">Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133</str>
  <int name="popularity">6</int>
  <float name="price">92.0</float>

  <str name="sku">SP2514N</str>
 </doc>
</result>
</response>

A simple query for one document, with a limited field list

http://yourhost.tld:9999/solr/select?q=id:SP2514N&version=2.1&indent=1&fl=id+name

<?xml version="1.0" encoding="UTF-8"?>
<response>
<responseHeader><status>0</status><QTime>2</QTime></responseHeader>

<result numFound="1" start="0">
 <doc>
  <str name="id">SP2514N</str>
  <str name="name">Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133</str>
 </doc>

</result>
</response>

A limited number of fields, plus the scores of the first 2 documents in the result set

http://yourhost.tld:9999/solr/select?q=cat:electronics+Belkin&version=2.1&start=0&rows=2&indent=on&fl=id+name+score

<?xml version="1.0" encoding="UTF-8"?>
<response>
<responseHeader><status>0</status><QTime>6</QTime></responseHeader>

<result numFound="14" start="0" maxScore="1.0851374">
 <doc>
  <float name="score">1.0851374</float>
  <str name="id">F8V7067-APL-KIT</str>
  <str name="name">Belkin Mobile Power Cord for iPod w/ Dock</str>

 </doc>
 <doc>
  <float name="score">0.68052477</float>
  <str name="id">IW-02</str>
  <str name="name">iPod &amp; iPod Mini USB 2.0 Cable</str>
 </doc>

</result>
</response>

The third and Fourth documents in the result set

http://yourhost.tld:9999/solr/select?q=cat:electronics+Belkin&version=2.1&start=2&rows=2&indent=on&fl=id+name+score

<?xml version="1.0" encoding="UTF-8"?>
<response>
<responseHeader><status>0</status><QTime>2</QTime></responseHeader>

<result numFound="14" start="2" maxScore="1.0851374">
 <doc>
  <float name="score">0.11182726</float>
  <str name="id">MA147LL/A</str>
  <str name="name">Apple 60 GB iPod with Video Playback Black</str>

 </doc>
 <doc>
  <float name="score">0.11182726</float>
  <str name="id">TWINX2048-3200PRO</str>
  <str name="name">CORSAIR XMS 2GB (2 x 1GB) 184-Pin DDR SDRAM Unbuffered DDR 400 (PC 3200) Dual Channel Kit System Memory - Retail</str>
 </doc>
</result>
</response>

The second document in the result set with debugging info (including its score explanation)

http://yourhost.tld:9999/solr/select?q=cat:electronics+Belkin&version=2.1&start=1&rows=1&indent=on&fl=id+name+score&debugQuery=on

<?xml version="1.0" encoding="UTF-8"?>
<response>
<responseHeader><status>0</status><QTime>13</QTime></responseHeader>

<result numFound="14" start="1" maxScore="1.0851374">
 <doc>
  <float name="score">0.68052477</float>
  <str name="id">IW-02</str>
  <str name="name">iPod &amp; iPod Mini USB 2.0 Cable</str>

 </doc>
</result>
<lst name="debug">
 <str name="querystring">cat:electronics Belkin</str>
 <str name="parsedquery">cat:electronics text:belkin</str>
 <lst name="explain">
  <str name="id=IW-02,internal_docid=3">
0.6805248 = sum of:
  0.22365452 = weight(cat:electronics in 3), product of:
    0.35784724 = queryWeight(cat:electronics), product of:
      1.0 = idf(docFreq=14)
      0.35784724 = queryNorm
    0.625 = fieldWeight(cat:electronics in 3), product of:
      1.0 = tf(termFreq(cat:electronics)=1)
      1.0 = idf(docFreq=14)
      0.625 = fieldNorm(field=cat, doc=3)
  0.4568703 = weight(text:belkin in 3), product of:
    0.9337802 = queryWeight(text:belkin), product of:
      2.609438 = idf(docFreq=2)
      0.35784724 = queryNorm
    0.4892696 = fieldWeight(text:belkin in 3), product of:
      1.0 = tf(termFreq(text:belkin)=1)
      2.609438 = idf(docFreq=2)
      0.1875 = fieldNorm(field=text, doc=3)
</str>
 </lst>

</lst>
</response>

One document in a result set, and the explain info for another document

http://localhost:8983/solr/select?q=cat:electronics+Belkin&version=2.1&start=1&rows=1&indent=on&fl=id+name+score&explainOther=id%3A6H500F0&debugQuery=on

<?xml version="1.0" encoding="UTF-8"?>
<response>
<responseHeader><status>0</status><QTime>7</QTime></responseHeader>

<result numFound="14" start="1" maxScore="1.0851374">
 <doc>
  <float name="score">0.68052477</float>
  <str name="id">IW-02</str>
  <str name="name">iPod &amp; iPod Mini USB 2.0 Cable</str>

 </doc>
</result>
<lst name="debug">
 <str name="querystring">cat:electronics Belkin</str>
 <str name="parsedquery">cat:electronics text:belkin</str>
 <lst name="explain">
  <str name="id=IW-02,internal_docid=3">
0.6805248 = sum of:
  0.22365452 = weight(cat:electronics in 3), product of:
    0.35784724 = queryWeight(cat:electronics), product of:
      1.0 = idf(docFreq=14)
      0.35784724 = queryNorm
    0.625 = fieldWeight(cat:electronics in 3), product of:
      1.0 = tf(termFreq(cat:electronics)=1)
      1.0 = idf(docFreq=14)
      0.625 = fieldNorm(field=cat, doc=3)
  0.4568703 = weight(text:belkin in 3), product of:
    0.9337802 = queryWeight(text:belkin), product of:
      2.609438 = idf(docFreq=2)
      0.35784724 = queryNorm
    0.4892696 = fieldWeight(text:belkin in 3), product of:
      1.0 = tf(termFreq(text:belkin)=1)
      2.609438 = idf(docFreq=2)
      0.1875 = fieldNorm(field=text, doc=3)
</str>
 </lst>

 <str name="otherQuery">id:6H500F0</str>
 <lst name="explainOther">
  <str name="id=6H500F0,internal_docid=1">
0.08946181 = product of:
  0.17892362 = weight(cat:electronics in 1), product of:
    0.35784724 = queryWeight(cat:electronics), product of:
      1.0 = idf(docFreq=14)
      0.35784724 = queryNorm
    0.5 = fieldWeight(cat:electronics in 1), product of:
      1.0 = tf(termFreq(cat:electronics)=1)
      1.0 = idf(docFreq=14)
      0.5 = fieldNorm(field=cat, doc=1)
  0.5 = coord(1/2)
</str>
 </lst>
</lst>
</response>

One document with highlighting

http://localhost:8983/solr/select/?stylesheet=&q=solr+xml&version=2.1&start=0&rows=10&indent=on&hl=true&hl.fl=features,sku&hl.snippets=3

<?xml version="1.0" encoding="UTF-8"?>
<response>
<responseHeader><status>0</status><QTime>3</QTime></responseHeader>

<result numFound="1" start="0">
 <doc>
  <arr name="cat"><str>software</str><str>search</str></arr>
  <arr name="features"><str>Advanced Full-Text Search Capabilities using Lucene</str><str>Optimizied for High Volume Web Traffic</str><str>Standards Based Open Interfaces - XML and HTTP</str>

	<str>Comprehensive HTML Administration Interfaces</str><str>Scalability - Efficient Replication to other Solr Search Servers</str><str>Flexible and Adaptable with XML configuration and Schema</str><str>Good unicode support: héllo (hello with an accent over the e)</str></arr>
  <str name="id">SOLR1000</str>
  <bool name="inStock">true</bool>
  <str name="manu">Apache Software Foundation</str>
  <str name="name">Solr, the Enterprise Search Server</str>

  <int name="popularity">10</int>
  <float name="price">0.0</float>
  <str name="sku">SOLR1000</str>
 </doc>
</result>
<lst name="highlighting">
 <lst name="SOLR1000">
  <arr name="features">

	<str>Standards Based Open Interfaces - &lt;em>XML&lt;/em> and HTTP</str>
	<str>Scalability - Efficient Replication to other &lt;em>Solr&lt;/em> Search Servers</str>
	<str>Flexible and Adaptable with &lt;em>XML&lt;/em> configuration and Schema</str>
  </arr>

  <arr name="sku">
	<str>&lt;em>SOLR&lt;/em>1000</str>
  </arr>
 </lst>
</lst>
</response>

CategorySolrRequestHandler

  • No labels