{"id":2647,"date":"2016-03-19T21:03:32","date_gmt":"2016-03-19T19:03:32","guid":{"rendered":"http:\/\/www.extradrm.com\/?p=2647"},"modified":"2020-10-05T21:09:46","modified_gmt":"2020-10-05T19:09:46","slug":"lucene-vs-solr","status":"publish","type":"post","link":"https:\/\/www.extradrm.com\/?p=2647","title":{"rendered":"Lucene vs SolR &#8230; Exact Search Problems"},"content":{"rendered":"<p><strong><em>Lucene and Solr are 2 differents Apache projects :<\/em><\/strong><\/p>\n<p>1) Lucene and Solr are <strong>NOT created<\/strong> to work together. Only Solr uses Lucene under the hood. Lucene has no clue about Solr API.<\/p>\n<p>2) Lucene is a powerful search engine framework that lets us add search capability to our application. It exposes easy-to-use API while hiding all the search-related complex operations. Any application can use this library, not just Solr.<\/p>\n<p>3) Solr is built around Lucene. It is not just a http-wrapper around Lucene but has been known to <strong>add more arsenal to Lucene<\/strong>. Solr is ready-to-use out of box. It is a web application that offers infrastructure related and a lot more features in addition to what Lucene offers.<\/p>\n<p>4) <strong>Lucene doesn&#8217;t just create the Index for the consumption by Solr<\/strong>. Lucene handles all the search related operations. Any application can use lucene framework.<\/p>\n<p>Examples are Solr, Elastic Search, LinkedIn (yes, under the hood), etc..<\/p>\n<div itemprop=\"text\">\n<p><strong>Lucene is a low level Java library<\/strong> (with ports to .NET, etc.) which implements indexing, analyzing, searching, etc.<\/p>\n<p>Solr is a standalone pre-configured product\/webapp which uses Lucene. If you prefer dealing with HTTP API instead of Java API, Solr is for you. Solr has also got some extra features on top (e.g. grouping).<\/p>\n<\/div>\n<p>A simple way to conceptualize the relationship between Solr and Lucene is that of a car and its engine. You can&#8217;t drive an engine, but you can drive a car. Similarly, Lucene is a programmatic library which you can&#8217;t use as-is, whereas Solr is a complete application which you can use out-of-box.<\/p>\n<p>At the heart of Lucene is an <tt>Index<\/tt>. You pump your data into the <tt>Index<\/tt>, then do searches on the <tt>Index<\/tt> to get results out. <tt>Document<\/tt> objects are stored in the <tt>Index<\/tt>, and it is your job to &#8220;convert&#8221; your data into <tt>Document<\/tt> objects and store them to the <tt>Index<\/tt>.<\/p>\n<h3>Adding a Document\/object to Index<\/h3>\n<p>Now you need to index your documents or business objects. To index an object, you use the Lucene <tt>Document<\/tt> class, to which you add the fields that you want indexed. As we briefly mentioned before, a Lucene <tt>Document<\/tt> is basically a container for a set of indexed fields. This is best illustrated by an example:<\/p>\n<pre>Document doc = new Document();\r\ndoc.add(new StringField(\"id\", \"Hotel-1345\", Field.Store.YES));\r\ndoc.add(new TextField(\"description\", \"A beautiful hotel\", Field.Store.YES));<\/pre>\n<p>In the above example, we add two fields, &#8220;id&#8221; and &#8220;description&#8221;, with the respective values &#8220;Hotel-1345&#8221; and &#8220;A beautiful hotel&#8221; to the document.<\/p>\n<p>More precisely, to add a field to a document, you create a new instance of the <tt>Field<\/tt> class, which can be either a <tt>StringField<\/tt> or a <tt>TextField<\/tt> (the difference between the two will be explained shortly). A field object takes the following three parameters:<\/p>\n<ul>\n<ul>\n<li><strong>Field name<\/strong>: This is the name of the field. In the above example, they are &#8220;id&#8221; and &#8220;description&#8221;.<\/li>\n<li><strong>Field value<\/strong>: This is the value of the field. In the above example, they are &#8220;Hotel-1345&#8221; and &#8220;A beautiful hotel&#8221;. A value can be a <tt>String<\/tt> like our example or a <tt>Reader<\/tt> if the object to be indexed is a file.<\/li>\n<li><strong>Storage flag<\/strong>: The third parameter specifies whether the actual value of the field needs to be stored in the lucene index or it can be discarded after it is indexed. Storing the value is useful if you need the value later, like you want to display it in the search result list or you use the value to look up a tuple from a database table, for example. If the value must be stored, use <tt>Field.Store.YES<\/tt>. You can also use <tt>Field.Store.COMPRESS<\/tt> for large documents or binary value fields. If you don&#8217;t need to store the value, use <tt>Field.Store.NO<\/tt>.<\/li>\n<\/ul>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>StringField vs TextField<\/strong>: In the above example, the &#8220;id&#8221; field contains the ID of the hotel, which is a single atomic value. In contrast, the &#8220;description&#8221; field contains an English text, which should be parsed (or &#8220;tokenized&#8221;) into a set of words for indexing. Use <tt>StringField<\/tt> for a field with an atomic value that should not be tokenized. Use <tt>TextField<\/tt> for a field that needs to be tokenized into a set of words. (<a title=\"Lucene sample Application\" href=\"http:\/\/oak.cs.ucla.edu\/cs144\/projects\/lucene\/\" target=\"_blank\" rel=\"noopener noreferrer\">Read more Here<\/a>) (<a href=\"http:\/\/www.extradrm.com\/wp-content\/uploads\/2016\/03\/lucene-tutorial.zip\">lucene-tutorial<\/a>)<\/p>\n<h2>When should I use Lucene then?<\/h2>\n<p>If you need to embed search functionality into a desktop application for example, Lucene is the more appropriate choice.<\/p>\n<p>For situations where you have very customized requirements requiring low-level access to the Lucene API classes, Solr may be more a hindrance than a help, since it is an extra layer of indirection.<\/p>\n<h2>What is Solr?<\/h2>\n<p><strong>Apache Solr is a web application<\/strong> built around Lucene with all kinds of goodies.<\/p>\n<p>It adds functionality like<\/p>\n<ul>\n<li>XML\/HTTP and JSON APIs<\/li>\n<li>Hit highlighting<\/li>\n<li>Faceted Search and Filtering<\/li>\n<li>Geospatial Search<\/li>\n<li>Fast Incremental Updates and Index Replication<\/li>\n<li>Caching<\/li>\n<li>Replication<\/li>\n<li>Web administration interface etc<\/li>\n<\/ul>\n<p>Unlike Lucene, Solr is a web application (WAR) which can be deployed in any servlet container, e.g. Jetty, Tomcat, Resin, etc.<\/p>\n<p>Solr can be installed and used by non-programmers. Lucene cannot.<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Some Extra Links around the subjets of search differences and serach problems related to razuna using Lucene in his Digital assets management :<\/strong><\/span><\/p>\n<p>http:\/\/forums.razuna.org\/topic\/razuna-search-not-working<br \/>\nhttps:\/\/help.razuna.com\/t\/razuna-1-7-search-isnt-working-at-all\/410\/5<br \/>\nhttps:\/\/help.razuna.com\/t\/other-language-analyzer-of-lucene\/772\/9<br \/>\nhttp:\/\/www.sitefinity.com\/blogs\/laurent-poulain&#8217;s-blog\/2015\/10\/12\/troubleshooting-lucene-search-issues<br \/>\nhttp:\/\/www.lucenetutorial.com\/lucene-vs-solr.html<br \/>\nhttp:\/\/stackoverflow.com\/questions\/4638671\/search-engine-lucene-vs-database-search<br \/>\nhttp:\/\/stackoverflow.com\/questions\/15704644\/difference-between-solr-and-lucene<br \/>\nhttps:\/\/www.linkedin.com\/pulse\/what-core-differences-among-lucenesolr-elasticsearch-nizam-muhammad<\/p>\n<p>https:\/\/doc.sitecore.net\/sitecore_experience_platform\/setting_up__maintaining\/search_and_indexing\/indexing\/using_solr_or_lucene<\/p>\n<p>http:\/\/www.lucenetutorial.com\/sample-apps\/textfileindexer-java.html<\/p>\n<p><a href=\"https:\/\/lingpipe-blog.com\/2014\/03\/08\/lucene-4-essentials-for-text-search-and-indexing\/\">Lucene 4 Essentials for Text Search and&nbsp;Indexing<\/a><br \/>\nhttp:\/\/stackoverflow.com\/questions\/9066347\/lucene-multi-word-phrases-as-search-terms<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lucene and Solr are 2 differents Apache projects : 1) Lucene and Solr are NOT created to work together. Only Solr uses Lucene under the hood. Lucene has no clue about Solr API. 2)&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":2847,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"youtube_video":null,"_links":{"self":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/2647"}],"collection":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2647"}],"version-history":[{"count":0,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/posts\/2647\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=\/wp\/v2\/media\/2847"}],"wp:attachment":[{"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2647"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2647"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.extradrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2647"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}