<?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>text &#8211; Solr.pl</title>
	<atom:link href="https://solr.pl/tag/text/feed/" rel="self" type="application/rss+xml" />
	<link>https://solr.pl</link>
	<description>All things to be found - Blog related to Apache Solr &#38; Lucene projects - https://solr.apache.org</description>
	<lastBuildDate>Sat, 14 Nov 2020 11:39:11 +0000</lastBuildDate>
	<language>pl-PL</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
	<item>
		<title>Solr Text Tagger &#8211; Szybkie spojrzenie w Solr 7.4</title>
		<link>https://solr.pl/2018/09/17/solr-text-tagger-szybkie-spojrzenie-w-solr-7-4/</link>
					<comments>https://solr.pl/2018/09/17/solr-text-tagger-szybkie-spojrzenie-w-solr-7-4/#respond</comments>
		
		<dc:creator><![CDATA[Rafał Kuć]]></dc:creator>
		<pubDate>Mon, 17 Sep 2018 10:38:43 +0000</pubDate>
				<category><![CDATA[Solr]]></category>
		<category><![CDATA[7.4.0]]></category>
		<category><![CDATA[solr]]></category>
		<category><![CDATA[tagger]]></category>
		<category><![CDATA[text]]></category>
		<guid isPermaLink="false">http://sematext.solr.pl/?p=762</guid>

					<description><![CDATA[Dawno nie publikowaliśmy żadnych treści o Solr, poza chwilami, kiedy wychodziła nowsza wersja tego silnika pełnotekstowego i biblioteki Lucene. Postanowiliśmy to zmienić i przyjrzeć się funkcjonalności tagowania tekstu, która wprowadzona została wraz z najnowszym wydaniem Solr. Umożliwia ona proste tagowanie]]></description>
										<content:encoded><![CDATA[
<p>Dawno nie publikowaliśmy żadnych treści o Solr, poza chwilami, kiedy wychodziła nowsza wersja tego silnika pełnotekstowego i biblioteki Lucene. Postanowiliśmy to zmienić i przyjrzeć się funkcjonalności tagowania tekstu, która wprowadzona została wraz z najnowszym wydaniem Solr. Umożliwia ona proste tagowanie oparte o wcześniej zdefiniowane dane, które mogą zawierać dodatkowe meta dane, jeżeli tylko chcemy. Spójrzmy więc, czego spodziewać się po tej funkcjonalności. </p>



<span id="more-762"></span>



<h3 class="wp-block-heading">Przygotowania</h3>



<p>Postaramy się, aby proces przygotowania bym najkrótszy z możliwych. W związku z tym zaczynamy uruchamiając instancję Solr w następujący sposób:</p>



<pre class="wp-block-preformatted brush:xml">$ bin/solr start -c -f</pre>



<p>Następnie tworzymy kolekcję o nazwie <em>test</em>:</p>



<pre class="wp-block-preformatted brush:xml">$ bin/solr create -c test</pre>



<p>Będziemy korzystać z domyślnej konfiguracji Solr, która pozwala nam zapomnieć o strukturze danych, przynajmniej w pewnych, ograniczonych warunkach. Należy pamiętać, aby nie wykorzystywać domyślnej konfiguracji, jako tej, z którą można iść na produkcję.</p>



<h3 class="wp-block-heading">Dane do tagowania<br></h3>



<p>Skupmy się <g class="gr_ gr_43 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="43" data-gr-id="43">na</g> chwilę <g class="gr_ gr_56 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="56" data-gr-id="56">na</g> <g class="gr_ gr_57 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="57" data-gr-id="57">danych</g>. Po <g class="gr_ gr_74 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="74" data-gr-id="74">pierwsze</g> <g class="gr_ gr_81 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="81" data-gr-id="81">potrzebujemy</g> <g class="gr_ gr_104 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="104" data-gr-id="104">danych</g>, które posłużą <g class="gr_ gr_160 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="160" data-gr-id="160">nam</g> jako te, którymi będziemy tagować. Na przykład użyjmy następujących nazwisk:</p>



<pre class="wp-block-preformatted brush:xml">Thomas Jefferson
Alexander Hamilton
George Washington
John Adams
James Wilkinson</pre>



<p>Aby przygotować je do tego, aby możliwe było skorzystanie z tagowania konieczna jest nieznaczna modyfikacja domyślnej konfiguracji &#8211; dodanie nowego typu pola, dodanie dwóch pól oraz kopiowania wartości jednego pola do drugiego. To wszystko możemy dodać do konfiguracji naszej kolekcji następującym poleceniem:</p>



<pre class="wp-block-preformatted brush:xml">$ curl -XPOST -H 'Content-type:application/json'  'http://localhost:8983/solr/test/schema' -d '{
  "add-field-type":{
    "name":"tag",
    "class":"solr.TextField",
    "postingsFormat":"FST50",
    "omitNorms":true,
    "omitTermFreqAndPositions":true,
    "indexAnalyzer":{
      "tokenizer":{ "class":"solr.StandardTokenizerFactory" },
      "filters":[
        {"class":"solr.LowerCaseFilterFactory"},
        {"class":"solr.ConcatenateGraphFilterFactory", "preservePositionIncrements":false }
      ]},
    "queryAnalyzer":{
      "tokenizer":{
         "class":"solr.StandardTokenizerFactory" },
      "filters":[
        {"class":"solr.LowerCaseFilterFactory"}
      ]}
    },
  "add-field":{"name":"name", "type":"text_general"},
  "add-field":{"name":"name_tag", "type":"tag", "stored":false},
  "add-copy-field":{"source":"name", "dest":["name_tag"]}
}'</pre>



<p>Zatrzymajmy się na chwilę i zastanówmy dlaczego dodaliśmy poszczególne elementy konfiguracji. Po pierwsze dodaliśmy nowy typ nazwany <em>tag</em>. Pozwala on funkcjonalności tagowania działać. Kluczowe są tak naprawdę dwie rzeczy &#8211; właściwość <em>postingsFormat</em> ustawiona na wartość <em>FST50</em> oraz filtr <em>solr.ConcatenateGraphFilterFactory</em>, jako ostatni filtr w trakcie indeksowania. </p>



<p>Następna sprawa to tagi. Potrzbujemy pola, które będzie przechowywać dane, pola, które będzie umożliwiło działanie tagera, czyli pól <em>name</em> oraz <em>name_tag</em>. I oczywiście automatycznego kopiowania. </p>



<p>Mając to wszystko możemy zaindeksować nasze tagi korzystając z następującego polecenia:</p>



<pre class="wp-block-preformatted brush:xml">$ curl -XPOST -H 'Content-type:application/json'  'http://localhost:8983/solr/test/update' -d '[
 {"name":"Thomas Jefferson"},
 {"name":"Alexander Hamilton"},
 {"name":"George Washington"},
 {"name":"John Adams"},
 {"name":"James Wilkinson"}
]'</pre>



<h3 class="wp-block-heading">Tagowanie tekstu</h3>



<p>Teraz, mając już zaindeksowane dane, które nas interesują możemy spróbować tagowania na tekście potencjalnie zawierającym te dane. Jednak przed tym dodajemy nowy requets handler korzystając z następującego polecenia:</p>



<pre class="wp-block-preformatted brush:xml">$ curl -XPOST -H 'Content-type:application/json' 'http://localhost:8983/solr/test/config' -d '{
 "add-requesthandler" : {
  "name": "/tagger",
  "class": "solr.TaggerRequestHandler",
  "defaults": {
   "field":"name_tag"
  }
 }
}'</pre>



<p>Powyższe polecenie dodaje nowy request handler o nazwie&nbsp; <em>/tagger</em> oparty o klasę <em>solr.TaggerRequestHandler</em>. Po tym możemy wreszcie wysłać zapytanie do nowego handlera:</p>



<pre class="wp-block-preformatted brush:xml">$ curl -X POST 'http://localhost:8983/solr/test/tagger?fl=id,name&amp;wt=json&amp;indent=on' <br>-H 'Content-Type:text/plain' -d 'George Washington (February 22, 
1732 December 14, 1799) was the first President of the United States 
(1789-1797), and was among the nation`s Founding Fathers. From 1775 
to 1783, he led the Patriot forces to victory over the British in 
the American Revolutionary War. He presided over the Constitutional 
Convention which formed the basis of the new federal government in 
Since the late 1780s, Washington has been known as the "Father 
of His Country" by compatriots. He is ranked by scholars among <br>the top presidents in history. Washington was born to a moderately 
prosperous family of planters, who owned slaves in colonial 
Virginia. He had early opportunities in education, learned 
mathematics and quickly launched a successful career as a surveyor, 
which in turn enabled him to make considerable land investments. He 
then joined the Virginia militia and fought in the French and Indian
War. During the American Revolutionary War, Washington was 
appointed commander-in-chief of the Continental Army, taking 
initiative in raids like those at Trenton, commanding in 
conventional battles such as the Battle of Monmouth, and 
coordinating a combined French-Patriot allied campaign at the Siege 
of Yorktown ending the conflict. His devotion to American 
Republicanism impelled him to decline further power after victory, 
and he resigned as commander-in-chief in 1783. Washington was born 
to a moderately prosperous family of planters, who owned slaves in 
colonial Virginia. He had early opportunities in education, learned 
mathematics and quickly launched a successful career as a surveyor, 
which in turn enabled him to make considerable land investments. He 
then joined the Virginia militia and fought in the French and Indian 
War. During the American Revolutionary War, Washington was appointed 
commander-in-chief of the Continental Army, taking initiative in 
raids like those at Trenton, commanding in conventional battles such 
as the Battle of Monmouth, and coordinating a combined French-Patriot 
allied campaign at the Siege of Yorktown ending the conflict. His 
devotion to American Republicanism impelled him to decline further 
power after victory, and he resigned as commander-
in-chief in 1783. Washington was among the countryís premier statesmen
and was unanimously chosen as president by the Electoral 
College in the first two national elections. He promoted and oversaw 
the implementation of a strong, well-financed national government. 
He remained impartial in the fierce rivalry between two cabinet 
secretaries, Thomas Jefferson and Alexander Hamilton, though he 
adopted Hamilton economic plans. When the French Revolution plunged 
Europe into war, Washington assumed a policy of neutrality 
to protect American shipsóalthough the controversial Jay Treaty of 
1795 normalized trade relations with Great Britain. Washington set 
precedents still in use today, such as the Cabinet advisory system, 
the inaugural address, the title "Mr. President", and a two-term 
limit. In his Farewell Address he gave a primer on civic virtue, 
warning of partisanship, sectionalism, and involvement in foreign 
wars. Washington inherited slaves at age eleven, prospered from slavery 
most of his life, and as late as 1793 officially supported other 
slaveholders. Eventually he became troubled with slavery and in his 
final will in 1799 he freed all his slaves. He is renowned for his 
religious toleration; his personal religion and devotion to 
Freemasonry have been debated. Upon his death, Washington was famously 
eulogized as "first in war, first in peace, and first in 
the hearts of his countrymen". He has been widely memorialized by 
monuments, public works, places, stamps, and currency. The nations capital, Washington D.C., and the state of Washington bear his name; and since 1932 the quarter dollar has carried his effigy.'</pre>



<p>Wynik zwrócony <g class="gr_ gr_5 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="5" data-gr-id="5">przez</g> Solr wygląda następująco:</p>



<pre class="wp-block-preformatted brush:xml">{<br>  "responseHeader":{
    "status":0,
    "QTime":2},
  "tagsCount":15,
  "tags":[[
      "startOffset",0,
      "endOffset",6,
      "ids",["d8d14516-7637-48c3-8042-ecf68b3822ef"]],
    [
      "startOffset",7,
      "endOffset",17,
      "ids",["d8d14516-7637-48c3-8042-ecf68b3822ef"]],
    [
      "startOffset",398,
      "endOffset",408,
      "ids",["d8d14516-7637-48c3-8042-ecf68b3822ef"]],
    [
      "startOffset",534,
      "endOffset",544,
      "ids",["d8d14516-7637-48c3-8042-ecf68b3822ef"]],
    [
      "startOffset",1693,
      "endOffset",1699,
      "ids",["7dad41c3-e607-4b6f-a86d-6d6490f48e4f"]],
    [
      "startOffset",1700,
      "endOffset",1709,
      "ids",["7dad41c3-e607-4b6f-a86d-6d6490f48e4f"]],
    [
      "startOffset",1714,
      "endOffset",1723,
      "ids",["5796481a-a698-4aa4-9666-9f5e4e565996"]],
    [
      "startOffset",1724,
      "endOffset",1732,
      "ids",["5796481a-a698-4aa4-9666-9f5e4e565996"]],
    [
      "startOffset",1752,
      "endOffset",1760,
      "ids",["5796481a-a698-4aa4-9666-9f5e4e565996"]],
    [
      "startOffset",1831,
      "endOffset",1841,
      "ids",["d8d14516-7637-48c3-8042-ecf68b3822ef"]],
    [
      "startOffset",1992,
      "endOffset",2002,
      "ids",["d8d14516-7637-48c3-8042-ecf68b3822ef"]],
    [
      "startOffset",2278,
      "endOffset",2288,
      "ids",["d8d14516-7637-48c3-8042-ecf68b3822ef"]],
    [
      "startOffset",2651,
      "endOffset",2661,
      "ids",["d8d14516-7637-48c3-8042-ecf68b3822ef"]],
    [
      "startOffset",2875,
      "endOffset",2885,
      "ids",["d8d14516-7637-48c3-8042-ecf68b3822ef"]],
    [
      "startOffset",2909,
      "endOffset",2919,
      "ids",["d8d14516-7637-48c3-8042-ecf68b3822ef"]]],
  "response":{"numFound":3,"start":0,"docs":[
      {
        "name":["Thomas Jefferson"],
        "id":"7dad41c3-e607-4b6f-a86d-6d6490f48e4f"},
      {
        "name":["Alexander Hamilton"],
        "id":"5796481a-a698-4aa4-9666-9f5e4e565996"},
      {
        "name":["George Washington"],
        "id":"d8d14516-7637-48c3-8042-ecf68b3822ef"}]
  }}</pre>



<p>Jak widać wzrócone zostały <g class="gr_ gr_69 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="69" data-gr-id="69">tagi</g> <g class="gr_ gr_75 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="75" data-gr-id="75">wraz</g> z ich występowaniem w tekście &#8211; każdy z <g class="gr_ gr_164 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="164" data-gr-id="164">nich</g> ma <g class="gr_ gr_202 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="202" data-gr-id="202">odpowiednie</g> <g class="gr_ gr_291 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="291" data-gr-id="291">informacje</g> pozwalające <g class="gr_ gr_315 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="315" data-gr-id="315">na</g> identyfikację. W <g class="gr_ gr_438 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="438" data-gr-id="438">ramach</g> <g class="gr_ gr_467 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="467" data-gr-id="467">odpowiedzi</g> od Solr dostaliśmy także listę <g class="gr_ gr_545 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="545" data-gr-id="545">znalezionych</g> tagów &#8211; w <g class="gr_ gr_651 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="651" data-gr-id="651">sumie</g> <g class="gr_ gr_662 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="662" data-gr-id="662">wszystko</g> co jest <g class="gr_ gr_732 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling" id="732" data-gr-id="732">potrzebne</g> <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>



<h3 class="wp-block-heading">Dodatkowe <g class="gr_ gr_17 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="17" data-gr-id="17">opcje</g> tagera</h3>



<p>Oczywiście Solr pozwala nam na kontrolę nowej funkcjonalności. Oprócz parametru <em>fl</em> oraz właściwości <em>field</em> możemy także korzystać z filtrów, definiować maksymalną ilość wyników, czy wybierać algortym radzący sobie z tagami, które zachodzą na siebie oraz kilka innych. Pełną listę opcji można znaleźć w oficjalnej dokumentacji Solr: <a href="https://lucene.apache.org/solr/guide/7_4/the-tagger-handler.html">https://lucene.apache.org/solr/guide/7_4/the-tagger-handler.html</a>.</p>



<h3 class="wp-block-heading">Wydajność</h3>



<p>Chcieliśmy także wspomnieć o kilku rzeczach związanych z wydajnością funkcjonalności tagowania tekstu. Po pierwsze, w wersji 7.4.0 Solr, handler tagowania nie jest w stanie przyjąć więcej, niż jednego dokumentu na raz. Oznacza to, iż nie ma łatwej możliwości wysyłania wielu dokumentów na raz. Oczywiście można sklejać dokumenty i wysyłać je jako pojedynczy ciąg tekstu, aczkolwiek nie jest to zbyt eleganckie rozwiązanie. Warto także pamiętać, iż tagowanie działa w oparciu o indeks Lucene i jest swego rodzaju wyszukiwaniem. Oznacza to, iż im mniej segmentów ma nasz indeks zawierający tagi, tym potencjalnie szybsze będą zapytania tagujące. Wartto więc zastanowić się nad optymalizacją kolekcji i wymuszeniem pojedynczego segmentu. </p>



<h3 class="wp-block-heading">Ograniczenia</h3>



<p>Ostatnia rzecz o której chcieliśmy wspomnieć to ograniczenia. W chwili pisania tego tekstu, czyli w wersji 7.4.0 Solr tagowanie możliwe jest tylko w przypadku kolekcji zbudowanej z pojedynczego shardu. Niewykluczone, iż zmieni się to w przyszłości, jednak na razie należy o tym pamiętać.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://solr.pl/2018/09/17/solr-text-tagger-szybkie-spojrzenie-w-solr-7-4/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
