<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>4.2 &#8211; Solr.pl</title>
	<atom:link href="https://solr.pl/en/tag/4-2-2/feed/" rel="self" type="application/rss+xml" />
	<link>https://solr.pl/en/</link>
	<description>All things to be found - Blog related to Apache Solr &#38; Lucene projects - https://solr.apache.org</description>
	<lastBuildDate>Thu, 12 Nov 2020 12:59:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
	<item>
		<title>Switch Query Parser &#8211; quick look</title>
		<link>https://solr.pl/en/2013/06/03/switch-query-parser-quick-look/</link>
					<comments>https://solr.pl/en/2013/06/03/switch-query-parser-quick-look/#respond</comments>
		
		<dc:creator><![CDATA[Rafał Kuć]]></dc:creator>
		<pubDate>Mon, 03 Jun 2013 11:59:28 +0000</pubDate>
				<category><![CDATA[Solr]]></category>
		<category><![CDATA[4.2]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[query parser]]></category>
		<category><![CDATA[solr]]></category>
		<category><![CDATA[switch]]></category>
		<category><![CDATA[SwitchQueryParser]]></category>
		<guid isPermaLink="false">http://sematext.solr.pl/?p=556</guid>

					<description><![CDATA[The number of different query parsers in Solr was always an amusement for me. Can someone here say how many of them are currently available and say what are those? Anyway, in this entry we won&#8217;t be talking about all]]></description>
										<content:encoded><![CDATA[<p>The number of different query parsers in Solr was always an amusement for me. Can someone here say how many of them are currently available and say what are those? Anyway, in this entry we won&#8217;t be talking about all the query parsers available in Solr, but we will take a quick look at one of them &#8211; the <em>SwitchQueryParser</em> introduced in Solr 4.2.</p>
<p><span id="more-556"></span></p>
<h3>Logic behind the parser</h3>
<p>The logic of the&nbsp;<em>SwitchQueryParser</em> is quite simple &#8211; allow processing a simple logic on the Solr side and add it as a sub-query. For example let&#8217;s say that we have an application that understand the following four values of the&nbsp;<em>priceRange</em> field:</p>
<ul>
<li><em>cheap</em> &#8211; when the price of the product (indexed in the&nbsp;<em>price</em> field) is lower than 10$,</li>
<li><em>average</em> &#8211; when the price is between 10 and 30$,</li>
<li><em>expensive</em> &#8211; when the product price is higher than&nbsp; 30$,</li>
<li><em>all</em> &#8211; in case we want to return all the documents without looking at the price.</li>
</ul>
<p>We want to have this logic stored in Solr somehow in order not to change our application or its configuration every time we want to change the above ranges. For this purpose we will use the <em>SwitchQueryParser</em>.</p>
<h3>Our query</h3>
<p>Let&#8217;s assume that our application will be able to send the following query:
</p>
<pre class="brush:bash">http://localhost:8983/solr/collection1/price?q=*:*&amp;priceRange=cheap</pre>
<p>We want the above query to return all the documents (<em>q=*:*</em>) narrowed to only those that are cheap, which in our case it will mean that they have price lower than 10$ (<em>priceRange=cheap </em>parameter).</p>
<h3>Solr configuration</h3>
<p>Of course we don&#8217;t want to send the <em>price</em> range in the query, because that wouldn&#8217;t make much sense for us. Because of that we decided to alter the <em>solrconfig.xml</em> file and add a new SearchHandler with the name of /<em>price</em>, which is configured as follows:
</p>
<pre class="brush:xml">&lt;requestHandler name="/price"&gt;
 &lt;lst name="defaults"&gt;
  &lt;str name="priceRange"&gt;all&lt;/str&gt;
 &lt;/lst&gt;
 &lt;lst name="appends"&gt;
  &lt;str name="fq"&gt;{!switch case.all='price:[* TO *]' case.cheap='price:[0 TO 10]' case.average='price:[10 TO 30]' case.expensive='price:[30 TO *]' v=$priceRange}&lt;/str&gt;
 &lt;/lst&gt;
&lt;/requestHandler&gt;</pre>
<p>As you can see the configuration of our SearchHandler consist of two elements. In the <em>defaults</em> section we defined the default value for the <em>priceRange</em> parameter, which is <em>all</em>. In addition to that, we&#8217;ve defined filter (<em>fq</em>) which is using the <em>SwitchQueryParser</em> (<em>!switch</em>). For each of the possible values the <em>priceRange</em> parameter can take (<em>v=$priceRange</em>) we defined a filter on the <em>price</em> field using the following expression &#8211;&nbsp;<em>case.priceRangeValue</em><em>=filter</em>. So, when the value of the <em>priceRange</em> parameter in the query will be equal to <strong><em>cheap</em></strong> than Solr will use the filter defined by the <em>case.<strong>cheap </strong></em>part of the filter definition, when the <em>priceRange</em> parameter value will be equal to <strong><em>expensive </em></strong>than Solr will use the filter defined by the <em>case.<strong>expensive </strong></em>and so on.</p>
<h3>What to remember about</h3>
<p>There is one crucial thing to remember when using the described parser. In our case, if we would <em>priceRange</em> parameter value different than the four mentioned it will result in Solr error.</p>
<h3>Summary</h3>
<p>In my opinion the <em>SwitchQueryParser</em> is a nice addition, although it is rather a feature that will be used by the minority of the users. However taking into consideration that is can help implementing some very basic logic and because it is simple (and thus not hungry for resources) there will be users which will find this nice query parser useful <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://solr.pl/en/2013/06/03/switch-query-parser-quick-look/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Solr 4.2: Index structure reading API</title>
		<link>https://solr.pl/en/2013/05/20/solr-4-2-index-structure-reading-api/</link>
					<comments>https://solr.pl/en/2013/05/20/solr-4-2-index-structure-reading-api/#respond</comments>
		
		<dc:creator><![CDATA[Rafał Kuć]]></dc:creator>
		<pubDate>Mon, 20 May 2013 11:58:51 +0000</pubDate>
				<category><![CDATA[Solr]]></category>
		<category><![CDATA[4.2]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[schema]]></category>
		<category><![CDATA[schema api]]></category>
		<category><![CDATA[schema.xml]]></category>
		<category><![CDATA[solr]]></category>
		<category><![CDATA[structure]]></category>
		<guid isPermaLink="false">http://sematext.solr.pl/?p=554</guid>

					<description><![CDATA[With the release of Solr 4.2 we&#8217;ve got the possibility to use the HTTP protocol to get information about Solr index structure. Of course, if one wanted to do that prior to Solr 4.2 it could be achieved by fetching]]></description>
										<content:encoded><![CDATA[<p>With the release of Solr 4.2 we&#8217;ve got the possibility to use the HTTP protocol to get information about Solr index structure. Of course, if one wanted to do that prior to Solr 4.2 it could be achieved by fetching the <em>schema.xml</em> file, parsing it and then getting the needed information. However when Solr 4.2 was released we&#8217;ve got a dedicated API which can return the information we need without the need of parsing the whole <em>schema.xml</em> file.</p>
<p><span id="more-554"></span></p>
<h3>Possibilities</h3>
<p>Let&#8217;s look at the new API by example.</p>
<h4>Getting information in XML format</h4>
<p>Many Solr users are used to getting their data in the XML format, at least when using Solr HTTP API. However, the schema API uses JSON as the default format. In order to get the data in the XML format in all the below examples, you&#8217;ll need to appeng the <em>wt=xml</em> parameter to the call, for example like that:
</p>
<pre class="brush:bash">$curl 'http://localhost:8983/solr/collection1/schema/fieldtypes?wt=xml'</pre>
<h4>Defined fields information</h4>
<p>Let&#8217;s start by looking at how to fetch information about the fields that are defined in Solr. In order to do that we have the following possibilities:</p>
<ol>
<li>Get information about all the fields defined in the index</li>
<li>Get information for a one, explicitly defined field</li>
</ol>
<p>In the first case we should use the following command:
</p>
<pre class="brush:bash">$curl 'http://localhost:8983/solr/collection1/schema/fields'</pre>
<p>In second case we should add the <em>/</em> character and the field name to the above command. For example in order to get the information about the <em>author</em> field we should use the following command:
</p>
<pre class="brush:bash">$curl 'http://localhost:8983/solr/collection1/schema/fields/author'</pre>
<p>Solr response for the first command will be similar to the following one:
</p>
<pre class="brush:plain">{
  "responseHeader":{
    "status":0,
    "QTime":1},
  "fields":[{
      "name":"_version_",
      "type":"long",
      "indexed":true,
      "stored":true},
    {
      "name":"author",
      "type":"text_general",
      "indexed":true,
      "stored":true},
    {
      "name":"cat",
      "type":"string",
      "multiValued":true,
      "indexed":true,
      "stored":true},
    {
      "name":"category",
      "type":"text_general",
      "indexed":true,
      "stored":true},
    {
      "name":"id",
      "type":"string",
      "multiValued":false,
      "indexed":true,
      "required":true,
      "stored":true,
      "uniqueKey":true},
    {
      "name":"url",
      "type":"text_general",
      "indexed":true,
      "stored":true},
    {
      "name":"weight",
      "type":"float",
      "indexed":true,
      "stored":true}]}</pre>
<p>On the other hand the response for the second command would be as follows:
</p>
<pre class="brush:plain">{
  "responseHeader":{
    "status":0,
    "QTime":0},
  "field":{
    "name":"author",
    "type":"text_general",
    "indexed":true,
    "stored":true}}</pre>
<h4>Getting information about defined dynamic fields</h4>
<p>Similar to what information we can get about the fields defined in the <em>schema.xml</em> we can get the information about dynamic fields. Again we have to options:</p>
<ol>
<li>Get information about all dynamic fields</li>
<li>Get information about specific dynamic field pattern</li>
</ol>
<p>In order to get all the information about dynamic fields we should use the following command:
</p>
<pre class="brush:bash">$curl 'http://localhost:8983/solr/collection1/schema/dynamicfields'</pre>
<p>In order to get information about a specific pattern we append the <em>/&nbsp;</em>character followed by the pattern, for example like this:
</p>
<pre class="brush:bash">$curl 'http://localhost:8983/solr/collection1/schema/dynamicfields/random_*'</pre>
<p>Solr will return the following response for the first query:
</p>
<pre class="brush:plain">{
  "responseHeader":{
    "status":0,
    "QTime":2},
  "dynamicfields":[{
      "name":"*_coordinate",
      "type":"tdouble",
      "indexed":true,
      "stored":false},
    {
      "name":"ignored_*",
      "type":"ignored",
      "multiValued":true},
    {
      "name":"random_*",
      "type":"random"},
    {
      "name":"*_p",
      "type":"location",
      "indexed":true,
      "stored":true},
    {
      "name":"*_c",
      "type":"currency",
      "indexed":true,
      "stored":true}]}</pre>
<p>And the following response will be returned for the second command:
</p>
<pre class="brush:plain">{
  "responseHeader":{
    "status":0,
    "QTime":1},
  "dynamicfield":{
    "name":"random_*",
    "type":"random"}}</pre>
<h4>Getting field types</h4>
<p>As you probably guess, in a way similar to the above describes examples, we can also get the information about the field types defined in our <em>schema.xml</em> files. We can fetch the following information:</p>
<ol>
<li>All the field types defined in the <em>schema.xml</em> file</li>
<li>A single type</li>
</ol>
<p>To get all the defined field types we should run the following command:
</p>
<pre class="brush:bash">$curl 'http://localhost:8983/solr/collection1/schema/fieldtypes'</pre>
<p>The get information about a single type we should again add the <em>/</em> character and append the field type name to it, for example like this:
</p>
<pre class="brush:bash">$curl 'http://localhost:8983/solr/collection1/schema/fieldtypes/text_gl'</pre>
<p>Solr will return the following information in response to the first command:
</p>
<pre class="brush:plain">{
  "responseHeader":{
    "status":0,
    "QTime":3},
  "fieldTypes":[{
      "name":"alphaOnlySort",
      "class":"solr.TextField",
      "sortMissingLast":true,
      "omitNorms":true,
      "analyzer":{
        "class":"solr.TokenizerChain",
        "tokenizer":{
          "class":"solr.KeywordTokenizerFactory"},
        "filters":[{
            "class":"solr.LowerCaseFilterFactory"},
          {
            "class":"solr.TrimFilterFactory"},
          {
            "class":"solr.PatternReplaceFilterFactory",
            "replace":"all",
            "replacement":"",
            "pattern":"([^a-z])"}]},
      "fields":[],
      "dynamicFields":[]},
    {
      "name":"boolean",
      "class":"solr.BoolField",
      "sortMissingLast":true,
      "fields":["inStock"],
      "dynamicFields":["*_bs",
        "*_b"]},
    {
      "name":"text_gl",
      "class":"solr.TextField",
      "positionIncrementGap":"100",
      "analyzer":{
        "class":"solr.TokenizerChain",
        "tokenizer":{
          "class":"solr.StandardTokenizerFactory"},
        "filters":[{
            "class":"solr.LowerCaseFilterFactory"},
          {
            "class":"solr.StopFilterFactory",
            "words":"lang/stopwords_gl.txt",
            "ignoreCase":"true",
            "enablePositionIncrements":"true"},
          {
            "class":"solr.GalicianStemFilterFactory"}]},
      "fields":[],
      "dynamicFields":[]},
    {
      "name":"tlong",
      "class":"solr.TrieLongField",
      "precisionStep":"8",
      "positionIncrementGap":"0",
      "fields":[],
      "dynamicFields":["*_tl"]}]}</pre>
<p>In response to the second command Solr will return the following:
</p>
<pre class="brush:plain">{
  "responseHeader":{
    "status":0,
    "QTime":2},
  "fieldType":{
    "name":"text_gl",
    "class":"solr.TextField",
    "positionIncrementGap":"100",
    "analyzer":{
      "class":"solr.TokenizerChain",
      "tokenizer":{
        "class":"solr.StandardTokenizerFactory"},
      "filters":[{
          "class":"solr.LowerCaseFilterFactory"},
        {
          "class":"solr.StopFilterFactory",
          "words":"lang/stopwords_gl.txt",
          "ignoreCase":"true",
          "enablePositionIncrements":"true"},
        {
          "class":"solr.GalicianStemFilterFactory"}]},
    "fields":[],
    "dynamicFields":[]}}</pre>
<p>As you can see, the amount information is nice as we are getting all the information about the field types and in addition to that the information which field are using give field (both dynamic and non-dynamic.</p>
<h4>Retrieving information about copyFields</h4>
<p>In addition to what we&#8217;ve discussed so far we are able to get information about copyFields section from the <em>schema.xml</em>. In order to do that one should run the following command:
</p>
<pre class="brush:bash">$curl 'http://localhost:8983/solr/collection1/schema/copyfields'</pre>
<p>And in response we will get the following data:
</p>
<pre class="brush:plain">{
  "responseHeader":{
    "status":0,
    "QTime":1},
  "copyfields":[{
      "source":"author",
      "dest":"text"},
    {
      "source":"cat",
      "dest":"text"},
    {
      "source":"content",
      "dest":"text"},
    {
      "source":"content_type",
      "dest":"text"},
    {
      "source":"description",
      "dest":"text"},
    {
      "source":"features",
      "dest":"text"},
    {
      "source":"author",
      "dest":"author_s",
      "destDynamicBase":"*_s"}]}</pre>
<h3>The future</h3>
<p>In Solr 4.3 the described API was improved and is now being prepared to enable not only reading of the index structure, but also writing modifications to it with the use of HTTP requests. We can expect that feature in one of the upcoming versions of Apache Solr, so its worth waiting in my opinion, at least by those who needs it.</p>
<p>W Solr 4.3 opisywane API zostało usprawnione oraz jest przygotowywane do umożliwienia zmian w strukturze indeksu za pomocą protokołu HTTP. Możemy zatem spodziewać się, iż w jednej z kolejnych wersji serwera wyszukiwania Solr otrzymamy możliwość łatwej zmiany struktury indeksu, przynajmniej takich, które nie będą powodować konfliktów z już zaindeksowanymi danymi.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://solr.pl/en/2013/05/20/solr-4-2-index-structure-reading-api/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
