{"id":91000,"date":"2020-06-23T11:00:00","date_gmt":"2020-06-23T08:00:00","guid":{"rendered":"https:\/\/examples.javacodegeeks.com\/?p=91000"},"modified":"2020-06-22T14:17:48","modified_gmt":"2020-06-22T11:17:48","slug":"apache-solr-function-query-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/","title":{"rendered":"Apache Solr Function Query Example"},"content":{"rendered":"<h2 class=\"wp-block-heading\">1. Introduction<\/h2>\n<p>In this example, we are going to explain what the Apache Solr Function Query is and how to use it in queries against our sample articles collection.<\/p>\n<h2 class=\"wp-block-heading\">2. Technologies Used<\/h2>\n<p>The steps and commands described in this example are for <a href=\"https:\/\/lucene.apache.org\/solr\/downloads.html#solr-852\">Apache Solr 8.5<\/a> on Windows 10. The JDK version we use to run the SolrCloud in this example is <a rel=\"noreferrer noopener\" href=\"https:\/\/jdk.java.net\/java-se-ri\/13\" target=\"_blank\">OpenJDK 13<\/a>.<\/p>\n<p>Before we start, please make sure your computer meets the <a rel=\"noreferrer noopener\" href=\"https:\/\/lucene.apache.org\/solr\/8_5_0\/SYSTEM_REQUIREMENTS.html\" target=\"_blank\">system requirements<\/a>. Also, please download the binary release of <a rel=\"noreferrer noopener\" href=\"https:\/\/lucene.apache.org\/solr\/downloads.html#solr-852\" target=\"_blank\">Apache Solr 8.5<\/a>.<br \/>In addition, it will save you some time if you can follow the <a rel=\"noreferrer noopener\" href=\"https:\/\/examples.javacodegeeks.com\/apache-solr-clustering-example\/\" target=\"_blank\">Apache Solr Clustering Example<\/a> to get a SolrCloud up and running on your local machine.<\/p>\n<\/p>\n<h2 class=\"wp-block-heading\">3. Function Queries Basics<\/h2>\n<p>When searching something in Solr, a common way is to specify terms as keywords in a query. The relevance score of each matching document in the search results is then calculated based on the terms&#8217; TF-IDF similarity. The relevance score is used to describe the degree in which a search result satisfies a user searching for information. The higher the relevance score the better a user&#8217;s requirement is met. Is there a way for us to generate relevance scores by using our custom calculation in a query so that the search results can satisfy our users&#8217; needs in different contexts? Function queries are introduced for this purpose.<\/p>\n<h3 class=\"wp-block-heading\">3.1 What Is A Function Query<\/h3>\n<p>A function query is a special query that can be added to a query and it allows us to specify a function to generate a relevance score at query time for each document in the search results. In addition, the calculated score can then be used to filter out documents, sort results, and append as a field for each document returned.<\/p>\n<h3 class=\"wp-block-heading\">3.2 Query Parsers Supporting Function Queries<\/h3>\n<p>The following query parsers support function queries:<\/p>\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/lucene.apache.org\/solr\/guide\/8_5\/the-standard-query-parser.html\" target=\"_blank\" rel=\"noreferrer noopener\">The Standard Query Parser<\/a><\/li>\n<li><a href=\"https:\/\/lucene.apache.org\/solr\/guide\/8_5\/the-dismax-query-parser.html\" target=\"_blank\" rel=\"noreferrer noopener\">The DisMax Query Parser<\/a><\/li>\n<li><a href=\"https:\/\/lucene.apache.org\/solr\/guide\/8_5\/the-extended-dismax-query-parser.html\" target=\"_blank\" rel=\"noreferrer noopener\">The Extended DisMax (eDismax) Query Parser<\/a><\/li>\n<li><a href=\"https:\/\/lucene.apache.org\/solr\/guide\/8_5\/other-parsers.html#function-query-parser\" target=\"_blank\" rel=\"noreferrer noopener\">The Function Query Parser<\/a><\/li>\n<li><a href=\"https:\/\/lucene.apache.org\/solr\/guide\/8_5\/other-parsers.html#function-range-query-parser\" target=\"_blank\" rel=\"noreferrer noopener\">Function Range Query Parser<\/a><\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">3.3. Function Syntax<\/h3>\n<p>Function queries use functions. The standard function syntax in Solr consists of a function name, an opening-round bracket, a list of parameters, and a closing round bracket.<\/p>\n<pre class=\"brush:bash\">numdocs()\nord(myIndexedField)\nmax(myfield,myotherfield,0)<\/pre>\n<p>In addition to the standard function syntax, there are three simplified function syntax as below:<\/p>\n<ul class=\"wp-block-list\">\n<li>A constant (a numeric or string literal)<\/li>\n<\/ul>\n<pre class=\"brush:bash\">18, 3.1415, \"Function Query Example\"<\/pre>\n<ul class=\"wp-block-list\">\n<li>A field<\/li>\n<\/ul>\n<pre class=\"brush:bash\">author, field(author)<\/pre>\n<ul class=\"wp-block-list\">\n<li>A parameter substitution<\/li>\n<\/ul>\n<pre class=\"brush:bash\">q={!func}max($f1,$f2)&amp;f1=views&amp;f2=1000<\/pre>\n<p>Note that Solr defines the input parameter types of a function as functions themselves. It means we can pass a function as a parameter of another function.<\/p>\n<h2 class=\"wp-block-heading\">4. Solr Function Queries Examples<\/h2>\n<p>There are several ways of using function queries in a Solr query. Before we show you some examples, let us prepare the collection and data for our queries.<\/p>\n<h3 class=\"wp-block-heading\">4.1 Upload A Configset<\/h3>\n<p>Before creating a collection to indexing our data, we need a configset for our collection. A configset is a collection of configuration files such as solrconfig.xml, synonyms.txt, the schema, etc.. There are two example configsets (<code>_default<\/code> and <code>sample_techproducts_configs<\/code>) in the Solr distribution which can be used when creating collections.<\/p>\n<p>Note that when running in SolrCloud mode, configsets are fundamentally stored in ZooKeeper and not the file system. Solr\u2019s <code>_default<\/code> configset is uploaded to ZooKeeper on initialization. So to use our own configset, we need to create a new one and upload it to ZooKeeper.<\/p>\n<p>For this example, we create our own configset <code>jcg_example_configs<\/code> for our collection simply by making a copy of the _default configset. Download the source code of this example and copy jcg_example_configs.zip to your working directory. For example, we copy <code>jcg_example_configs.zip<\/code> to <code>D:\\<\/code> on Windows 10. Then run the following command in a Command Prompt to upload a configset:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:bash\">curl -X POST --header \"Content-Type:application\/octet-stream\" --data-binary @jcg_example_configs.zip \"http:\/\/localhost:8983\/solr\/admin\/configs?action=UPLOAD&amp;name=jcg_example_configs\"<\/pre>\n<p>We can see the output as below:<\/p>\n<pre class=\"brush:bash\">D:\\&gt;curl -X POST --header \"Content-Type:application\/octet-stream\" --data-binary @jcg_example_configs.zip \"http:\/\/localhost:8983\/solr\/admin\/configs?action=UPLOAD&amp;name=jcg_example_configs\"\n{\n  \"responseHeader\":{\n    \"status\":0,\n    \"QTime\":2203}}<\/pre>\n<p>If the <code>jcg_example_config<\/code> configset has already existed, you can delete it with the following command:<\/p>\n<pre class=\"brush:bash\">curl -X DELETE http:\/\/localhost:8983\/api\/cluster\/configs\/jcg_example_configs?omitHeader=true<\/pre>\n<p>Now we can use the <a href=\"https:\/\/lucene.apache.org\/solr\/guide\/8_5\/configsets-api.html#configsets-api\" target=\"_blank\" rel=\"noreferrer noopener\">Configsets API<\/a> to list all configsets on the SolrCloud:<\/p>\n<pre class=\"brush:bash\">curl http:\/\/localhost:8983\/solr\/admin\/configs?action=LIST<\/pre>\n<p>There are two configsets in the response:<\/p>\n<pre class=\"brush:bash\">D:\\&gt;curl http:\/\/localhost:8983\/solr\/admin\/configs?action=LIST\n{\n  \"responseHeader\":{\n    \"status\":0,\n    \"QTime\":1},\n  \"configSets\":[\"jcg_example_configs\",\n    \"_default\"]}<\/pre>\n<h3 class=\"wp-block-heading\">4.2 Indexing Data<\/h3>\n<p>Assuming that you have followed the steps in <a rel=\"noreferrer noopener\" href=\"https:\/\/examples.javacodegeeks.com\/apache-solr-clustering-example\/\" target=\"_blank\">Apache Solr Clustering Example<\/a> to get a SolrCloud up and running on your local machine. Open <a rel=\"noreferrer noopener\" href=\"http:\/\/localhost:8983\/solr\/\" target=\"_blank\">Solr Admin<\/a> in a browser and create a new collection named <code>jcgArticles<\/code> with <code>jcg_example_configs<\/code> config set. Select the newly created <code>jcgArticles<\/code> collection and go to <code>Documents<\/code> screen, Copy the content of <code>articles.csv<\/code> file downloaded from this example and paste into <code>Documents<\/code> text box. Select <code>CSV<\/code> from the drop-down list as <code>Document Type<\/code> and click <code>Submit Document<\/code> button.<\/p>\n<div class=\"wp-block-image is-style-default\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"1107\" height=\"750\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/preparing-data-w.jpg\" alt=\"Solr Function Query - Preparing Data\" class=\"wp-image-91005\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/preparing-data-w.jpg 1107w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/preparing-data-w-300x203.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/preparing-data-w-1024x694.jpg 1024w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/preparing-data-w-768x520.jpg 768w\" sizes=\"(max-width: 1107px) 100vw, 1107px\" \/><figcaption>Fig. 1. Preparing Data<\/figcaption><\/figure>\n<\/div>\n<p>You will see the following output once documents have been submitted successfully.<\/p>\n<pre class=\"brush:bash\"> Status: success\nResponse:\n{\n  \"responseHeader\": {\n    \"rf\": 2,\n    \"status\": 0,\n    \"QTime\": 467\n  }\n}<\/pre>\n<h3 class=\"wp-block-heading\">4.3 Querying Without Using A Function Query<\/h3>\n<p>We search for articles whose title contains term <code>SolrCloud<\/code> by using a field query. Also, we add <code>score<\/code> to the fields list of the search results. Later, We will compare the relevance scores returned by this query to the relevance scores of other queries using function queries.<\/p>\n<pre class=\"brush:bash\"> q=title:*SolrCloud*&amp;fl=*,score<\/pre>\n<div class=\"wp-block-image is-style-default\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"1107\" height=\"799\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/query-without-function-query-w.jpg\" alt=\"Solr Function Query - Querying Without Using A Function Query\" class=\"wp-image-91008\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/query-without-function-query-w.jpg 1107w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/query-without-function-query-w-300x217.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/query-without-function-query-w-1024x739.jpg 1024w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/query-without-function-query-w-768x554.jpg 768w\" sizes=\"(max-width: 1107px) 100vw, 1107px\" \/><figcaption>Fig. 2. Querying Without Using A Function Query<\/figcaption><\/figure>\n<\/div>\n<p>Click the <code>Execute Query<\/code> button and the output would be:<\/p>\n<pre class=\"brush:bash\">{\n  \"responseHeader\":{\n    \"zkConnected\":true,\n    \"status\":0,\n    \"QTime\":104,\n    \"params\":{\n      \"q\":\"title:*SolrCloud*\",\n      \"fl\":\"*,score\",\n      \"wt\":\"json\",\n      \"_\":\"1592054831147\"}},\n  \"response\":{\"numFound\":2,\"start\":0,\"maxScore\":1.0,\"docs\":[\n      {\n        \"id\":\"0818231712\",\n        \"category\":[\"solr\"],\n        \"title\":[\"Apache SolrCloud Example\"],\n        \"published\":true,\n        \"author\":[\"Kevin Yang\"],\n        \"views\":2000,\n        \"likes\":1000,\n        \"dislikes\":10,\n        \"comments\":200,\n        \"publish_date\":\"2020-06-05T00:00:00Z\",\n        \"_version_\":1669390419809533952,\n        \"score\":1.0},\n      {\n        \"id\":\"0380014300\",\n        \"category\":[\"solr\"],\n        \"title\":[\"SolrCloud Tutorial\"],\n        \"published\":true,\n        \"author\":[\"Roger Goodwill\"],\n        \"views\":2000,\n        \"likes\":1000,\n        \"dislikes\":500,\n        \"comments\":10,\n        \"publish_date\":\"2020-06-05T00:00:00Z\",\n        \"_version_\":1669390419821068288,\n        \"score\":1.0}]\n  }}<\/pre>\n<p>As we can see from the output above, there are <code>2<\/code> articles found. Both of them with a score of 1.0 and the number of views is the same 2000. How do we know which article is more popular? You may notice that these two articles have a different number of dislikes. So we can define the popularity of an article as below:<\/p>\n<pre class=\"brush:bash\">popularity = views \/ dislikes<\/pre>\n<p>It means if two articles have the same number of views, then the article with less dislikes is more popular than the other one. Let&#8217;s see how we can implement this popularity calculation and use it with a function query.[ulp id=&#8217;nVHijykNs8bcCQYH&#8217;]<\/p>\n<h3 class=\"wp-block-heading\">4.4 Querying With A Function Query<\/h3>\n<p>Query parsers such as <code>func<\/code> and <code>frange<\/code> expect function arguments. We can use the built-in Solr function <a href=\"https:\/\/lucene.apache.org\/solr\/guide\/8_5\/function-queries.html#div-function\" target=\"_blank\" rel=\"noreferrer noopener\">div<\/a> to calculate the popularity. For example:<\/p>\n<pre class=\"brush:bash\">q=title:*SolrCloud* AND _query_:\"{!func}div(views,dislikes)\"&amp;fq={!frange l=1}dislikes&amp;fl=*,score<\/pre>\n<p>In this query, we add <code>{!func}div(views,dislikes)<\/code> function to the query and include the <em>score in the fields list returned. In addition, fq={!frange l=1}dislikes are used to avoid division by zero issues<\/em>. The output would be:<\/p>\n<pre class=\"brush:bash\">{\n  \"responseHeader\":{\n    \"zkConnected\":true,\n    \"status\":0,\n    \"QTime\":97,\n    \"params\":{\n      \"q\":\"title:*SolrCloud* AND _query_:\\\"{!func}div(views,dislikes)\\\"\",\n      \"fl\":\"*,score\",\n      \"fq\":\"{!frange l=1}dislikes\",\n      \"wt\":\"json\",\n      \"_\":\"1592054952916\"}},\n  \"response\":{\"numFound\":2,\"start\":0,\"maxScore\":201.0,\"docs\":[\n      {\n        \"id\":\"0818231712\",\n        \"category\":[\"solr\"],\n        \"title\":[\"Apache SolrCloud Example\"],\n        \"published\":true,\n        \"author\":[\"Kevin Yang\"],\n        \"views\":2000,\n        \"likes\":1000,\n        \"dislikes\":10,\n        \"comments\":200,\n        \"publish_date\":\"2020-06-05T00:00:00Z\",\n        \"_version_\":1669390419809533952,\n        \"score\":201.0},\n      {\n        \"id\":\"0380014300\",\n        \"category\":[\"solr\"],\n        \"title\":[\"SolrCloud Tutorial\"],\n        \"published\":true,\n        \"author\":[\"Roger Goodwill\"],\n        \"views\":2000,\n        \"likes\":1000,\n        \"dislikes\":500,\n        \"comments\":10,\n        \"publish_date\":\"2020-06-05T00:00:00Z\",\n        \"_version_\":1669390419821068288,\n        \"score\":5.0}]\n  }}<\/pre>\n<p>Now we can see that the relevance scores have been updated. The first article has a score of 201.0 and the second article has a score <code>5.0<\/code>. Obviously, the first article is more popular than the second one based on our popularity definition.<\/p>\n<p>The query above can be written via the <code>_val_<\/code> keyword as well:<\/p>\n<pre class=\"brush:bash\">q=title:*SolrCloud* AND _val_:\"div(views,dislikes)\"&amp;fq={!frange l=1}dislikes&amp;fl=*,score<\/pre>\n<p>It yields the same output:<\/p>\n<pre class=\"brush:bash\">{\n  \"responseHeader\":{\n    \"zkConnected\":true,\n    \"status\":0,\n    \"QTime\":50,\n    \"params\":{\n      \"q\":\"title:*SolrCloud* AND _val_:\\\"div(views,dislikes)\\\"\",\n      \"fl\":\"*,score\",\n      \"fq\":\"{!frange l=1}dislikes\",\n      \"wt\":\"json\",\n      \"_\":\"1592054952916\"}},\n  \"response\":{\"numFound\":2,\"start\":0,\"maxScore\":201.0,\"docs\":[\n      {\n        \"id\":\"0818231712\",\n        \"category\":[\"solr\"],\n        \"title\":[\"Apache SolrCloud Example\"],\n        \"published\":true,\n        \"author\":[\"Kevin Yang\"],\n        \"views\":2000,\n        \"likes\":1000,\n        \"dislikes\":10,\n        \"comments\":200,\n        \"publish_date\":\"2020-06-05T00:00:00Z\",\n        \"_version_\":1669390419809533952,\n        \"score\":201.0},\n      {\n        \"id\":\"0380014300\",\n        \"category\":[\"solr\"],\n        \"title\":[\"SolrCloud Tutorial\"],\n        \"published\":true,\n        \"author\":[\"Roger Goodwill\"],\n        \"views\":2000,\n        \"likes\":1000,\n        \"dislikes\":500,\n        \"comments\":10,\n        \"publish_date\":\"2020-06-05T00:00:00Z\",\n        \"_version_\":1669390419821068288,\n        \"score\":5.0}]\n  }}<\/pre>\n<h3 class=\"wp-block-heading\">4.5 Using Function Query In A Sort Expression<\/h3>\n<p>Function queries can be used in a sort expression. For example:<\/p>\n<pre class=\"brush:bash\">q=title:*SolrCloud*&amp;fq={!frange l=1}dislikes&amp;fl=*,score&amp;sort=div(views,dislikes) desc, score desc<\/pre>\n<p>In this query, instead of using our popularity function for the relevance score, we just add it in the sort expression to sort the results by the popularity in descending order. The output would be:<\/p>\n<pre class=\"brush:bash\">{\n  \"responseHeader\":{\n    \"zkConnected\":true,\n    \"status\":0,\n    \"QTime\":72,\n    \"params\":{\n      \"q\":\"title:*SolrCloud*\",\n      \"fl\":\"*,score\",\n      \"fq\":\"{!frange l=1}dislikes\",\n      \"sort\":\"div(views,dislikes) desc, score desc\",\n      \"wt\":\"json\",\n      \"_\":\"1592061341139\"}},\n  \"response\":{\"numFound\":2,\"start\":0,\"maxScore\":1.0,\"docs\":[\n      {\n        \"id\":\"0818231712\",\n        \"category\":[\"solr\"],\n        \"title\":[\"Apache SolrCloud Example\"],\n        \"published\":true,\n        \"author\":[\"Kevin Yang\"],\n        \"views\":2000,\n        \"likes\":1000,\n        \"dislikes\":10,\n        \"comments\":200,\n        \"publish_date\":\"2020-06-05T00:00:00Z\",\n        \"_version_\":1669390419809533952,\n        \"score\":1.0},\n      {\n        \"id\":\"0380014300\",\n        \"category\":[\"solr\"],\n        \"title\":[\"SolrCloud Tutorial\"],\n        \"published\":true,\n        \"author\":[\"Roger Goodwill\"],\n        \"views\":2000,\n        \"likes\":1000,\n        \"dislikes\":500,\n        \"comments\":10,\n        \"publish_date\":\"2020-06-05T00:00:00Z\",\n        \"_version_\":1669390419821068288,\n        \"score\":1.0}]\n  }}<\/pre>\n<p>We can see that the relevance scores remain the same but the article with higher popularity value is put in front.<\/p>\n<h3 class=\"wp-block-heading\">4.6 Adding Function Results As Fields Of Documents In Search Results<\/h3>\n<p>Another useful scenario is to add the calculation results as fields of documents in the search results. For instance:<\/p>\n<pre class=\"brush:bash\">q=title:*SolrCloud*&amp;fq={!frange l=1}dislikes&amp;fl=id,title,author,views,dislikes,score,popularity:div(views,dislikes)<\/pre>\n<p>In this query, we add a pseudo-field <code>popularity:div(views,dislikes)<\/code> to the fields list. The output would be:<\/p>\n<pre class=\"brush:bash\">{\n  \"responseHeader\":{\n    \"zkConnected\":true,\n    \"status\":0,\n    \"QTime\":84,\n    \"params\":{\n      \"q\":\"title:*SolrCloud*\",\n      \"fl\":\"id,title,author,views,dislikes,score,popularity:div(views,dislikes)\",\n      \"fq\":\"{!frange l=1}dislikes\",\n      \"wt\":\"json\",\n      \"_\":\"1592061341139\"}},\n  \"response\":{\"numFound\":2,\"start\":0,\"maxScore\":1.0,\"docs\":[\n      {\n        \"id\":\"0818231712\",\n        \"title\":[\"Apache SolrCloud Example\"],\n        \"author\":[\"Kevin Yang\"],\n        \"views\":2000,\n        \"dislikes\":10,\n        \"popularity\":200.0,\n        \"score\":1.0},\n      {\n        \"id\":\"0380014300\",\n        \"title\":[\"SolrCloud Tutorial\"],\n        \"author\":[\"Roger Goodwill\"],\n        \"views\":2000,\n        \"dislikes\":500,\n        \"popularity\":4.0,\n        \"score\":1.0}]\n  }}<\/pre>\n<p>There is a list of available Function Queries available <a rel=\"noreferrer noopener\" href=\"https:\/\/lucene.apache.org\/solr\/guide\/8_5\/function-queries.html\" target=\"_blank\">here<\/a>. Also, you can implement your own custom functions and use them in the query which is out of the scope of this example.<\/p>\n<h2 class=\"wp-block-heading\">5. Download the Sample Configuration and Data Files<\/h2>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the sample configuration and data files of this example here: <a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/06\/apache-solr-function-query-example.zip\"><strong>Apache Solr Function Query Example<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction In this example, we are going to explain what the Apache Solr Function Query is and how to use it in queries against our sample articles collection. 2. Technologies Used The steps and commands described in this example are for Apache Solr 8.5 on Windows 10. The JDK version we use to run &hellip;<\/p>\n","protected":false},"author":223,"featured_media":25294,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[949],"tags":[946,1220,44576,44241],"class_list":["post-91000","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apache-solr","tag-apache-solr","tag-example","tag-function-query","tag-solrcloud"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Apache Solr Function Query Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"1. Introduction In this example, we are going to explain what the Apache Solr Function Query is and how to use it in queries against our sample articles\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apache Solr Function Query Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"1. Introduction In this example, we are going to explain what the Apache Solr Function Query is and how to use it in queries against our sample articles\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-23T08:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/apache-solr-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Kevin Yang\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kevin Yang\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/\"},\"author\":{\"name\":\"Kevin Yang\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/3f6ff013b8204dc7f5e6d2660fbc9f8f\"},\"headline\":\"Apache Solr Function Query Example\",\"datePublished\":\"2020-06-23T08:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/\"},\"wordCount\":1189,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/apache-solr-logo.jpg\",\"keywords\":[\"Apache Solr\",\"example\",\"Function Query\",\"SolrCloud\"],\"articleSection\":[\"Apache Solr\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/\",\"name\":\"Apache Solr Function Query Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/apache-solr-logo.jpg\",\"datePublished\":\"2020-06-23T08:00:00+00:00\",\"description\":\"1. Introduction In this example, we are going to explain what the Apache Solr Function Query is and how to use it in queries against our sample articles\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/apache-solr-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/apache-solr-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Apache Solr\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/apache-solr\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Apache Solr Function Query Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/3f6ff013b8204dc7f5e6d2660fbc9f8f\",\"name\":\"Kevin Yang\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2efb55f26af9d8752be93a78f2cdd9b2529df1f087c7b8901b68dbe11b7cf5ee?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2efb55f26af9d8752be93a78f2cdd9b2529df1f087c7b8901b68dbe11b7cf5ee?s=96&d=mm&r=g\",\"caption\":\"Kevin Yang\"},\"description\":\"A software design and development professional with seventeen years\u2019 experience in the IT industry, especially with Java EE and .NET, I have worked for software companies, scientific research institutes and websites.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/kevinyang2050\/\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/kevin-yang\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Apache Solr Function Query Example - Java Code Geeks","description":"1. Introduction In this example, we are going to explain what the Apache Solr Function Query is and how to use it in queries against our sample articles","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/","og_locale":"en_US","og_type":"article","og_title":"Apache Solr Function Query Example - Java Code Geeks","og_description":"1. Introduction In this example, we are going to explain what the Apache Solr Function Query is and how to use it in queries against our sample articles","og_url":"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2020-06-23T08:00:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/apache-solr-logo.jpg","type":"image\/jpeg"}],"author":"Kevin Yang","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Kevin Yang","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/"},"author":{"name":"Kevin Yang","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/3f6ff013b8204dc7f5e6d2660fbc9f8f"},"headline":"Apache Solr Function Query Example","datePublished":"2020-06-23T08:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/"},"wordCount":1189,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/apache-solr-logo.jpg","keywords":["Apache Solr","example","Function Query","SolrCloud"],"articleSection":["Apache Solr"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/","url":"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/","name":"Apache Solr Function Query Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/apache-solr-logo.jpg","datePublished":"2020-06-23T08:00:00+00:00","description":"1. Introduction In this example, we are going to explain what the Apache Solr Function Query is and how to use it in queries against our sample articles","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/apache-solr-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/07\/apache-solr-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/apache-solr-function-query-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/"},{"@type":"ListItem","position":4,"name":"Apache Solr","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/apache-solr\/"},{"@type":"ListItem","position":5,"name":"Apache Solr Function Query Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/3f6ff013b8204dc7f5e6d2660fbc9f8f","name":"Kevin Yang","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2efb55f26af9d8752be93a78f2cdd9b2529df1f087c7b8901b68dbe11b7cf5ee?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2efb55f26af9d8752be93a78f2cdd9b2529df1f087c7b8901b68dbe11b7cf5ee?s=96&d=mm&r=g","caption":"Kevin Yang"},"description":"A software design and development professional with seventeen years\u2019 experience in the IT industry, especially with Java EE and .NET, I have worked for software companies, scientific research institutes and websites.","sameAs":["https:\/\/www.linkedin.com\/in\/kevinyang2050\/"],"url":"https:\/\/examples.javacodegeeks.com\/author\/kevin-yang\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/91000","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/223"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=91000"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/91000\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/25294"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=91000"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=91000"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=91000"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}