This is the code which i have written to get the stemmed word. public class URLConnectionReader { public static void main(String[] args) throws Exception { URL solr = new URL( "http://localhost:8983/solr/ "+args[0]+"/analysis/field?wt=json&analysis.showmatch=true&analysis.query="+args[1]+"&analysis.fieldtype="+args[2]+""); URLConnection sl = solr.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader( sl.getInputStream())); String inputLine; StringBuilder sb = new StringBuilder(); while ((inputLine = in.readLine()) != null) { sb.append(inputLine); }
in.close(); JSONObject obj = new JSONObject(sb.toString()); JSONArray analysis = obj.getJSONObject("analysis") .getJSONObject("field_types").getJSONObject(args[2]) .getJSONArray("query"); JSONArray jsonarray = new JSONArray(analysis.toString()); ArrayList<String> stemmedWords = new ArrayList<String>(); for (int i = 0; i < jsonarray.length(); i++) { String objF = jsonarray.getString(i); stemmedWords.add(objF); } String lastStemmedGroup = stemmedWords.get(stemmedWords.size() - 1).toString(); JSONArray finalStemmer = new JSONArray(lastStemmedGroup); for (int i = 0; i < finalStemmer.length(); i++) { JSONObject jsonobject = finalStemmer.getJSONObject(i); String stemmedWord = jsonobject.getString("text"); System.out.println(stemmedWord); } } } Here, args[0] is core. args[1] is the word i'll be sending for stemming. args[2] is the Analyse Fieldname / FieldType. I am looking into FieldAnalysisRequest. Do you have some code snippet or something which can guide me ? Thanks On Fri, Sep 4, 2015 at 12:44 PM, Upayavira <u...@odoko.co.uk> wrote: > Yes, look at the one I mentioned further up in this thread, which is a > part of SolrJ: FieldAnalysisRequest > > That uses the same HTTP call in the backend, but formats the result in a > Java friendly manner. > > Upayavira > > On Fri, Sep 4, 2015, at 05:52 AM, Ritesh Sinha wrote: > > Yeah, I got. Thanks. > > > > It returns a json which have the stemmed words.I just need to parse it > > and > > get the value. > > > > But, isn't there any JAVA API available for it ? > > > > On Thu, Sep 3, 2015 at 7:58 PM, Upayavira <u...@odoko.co.uk> wrote: > > > > > yes, the URL should be something like: > > > > > > > > > > http://localhost:8983/solr/images/analysis/field?wt=json&analysis.showmatch=true&analysis.fieldvalue= > > > <stuff-you-want-analysing>&analysis.fieldname=<somefield> > > > > > > Upayavira > > > > > > On Thu, Sep 3, 2015, at 03:23 PM, Jack Krupansky wrote: > > > > The # in the URL says to send the request to the admin UI, which of > > > > course > > > > returns an HTML web page. Instead, send the analysis URL fragment > > > > directly > > > > to the analysis API (not UI) for the Solr core, without the #. > > > > > > > > -- Jack Krupansky > > > > > > > > On Thu, Sep 3, 2015 at 8:45 AM, Ritesh Sinha < > > > > kumarriteshranjansi...@gmail.com> wrote: > > > > > > > > > Hi, > > > > > > > > > > I observed the inspect element and wrote a code to give back the > > > content. I > > > > > have included the url which was getting generated. > > > > > > > > > > public class URLConnectionReader { > > > > > public static void main(String[] args) throws Exception { > > > > > URL solr = new URL( > > > > > " > > > > > > > > > > > > > > http://localhost:8983/solr/#/testcore/analysis?analysis.fieldvalue=holidays&analysis.fieldtype=inferlytics&verbose_output=1 > > > > > "); > > > > > URLConnection sl = solr.openConnection(); > > > > > BufferedReader in = new BufferedReader(new > InputStreamReader( > > > > > sl.getInputStream())); > > > > > String inputLine; > > > > > > > > > > while ((inputLine = in.readLine()) != null) > > > > > System.out.println(inputLine); > > > > > in.close(); > > > > > } > > > > > } > > > > > > > > > > > > > > > But it shows this in the consloe : > > > > > > > > > > <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" " > > > > > http://www.w3.org/TR/html4/strict.dtd"> > > > > > <html> > > > > > > > > > > <!-- > > > > > Licensed to the Apache Software Foundation (ASF) under one or more > > > > > contributor license agreements. See the NOTICE file distributed > with > > > > > this work for additional information regarding copyright ownership. > > > > > The ASF licenses this file to You under the Apache License, > Version 2.0 > > > > > (the "License"); you may not use this file except in compliance > with > > > > > the License. You may obtain a copy of the License at > > > > > > > > > > http://www.apache.org/licenses/LICENSE-2.0 > > > > > > > > > > Unless required by applicable law or agreed to in writing, software > > > > > distributed under the License is distributed on an "AS IS" BASIS, > > > > > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or > > > implied. > > > > > See the License for the specific language governing permissions and > > > > > limitations under the License. > > > > > --> > > > > > > > > > > <head> > > > > > > > > > > <title>Solr Admin</title> > > > > > > > > > > <link rel="icon" type="image/x-icon" > href="img/favicon.ico?_=5.3.0"> > > > > > <link rel="shortcut icon" type="image/x-icon" > > > > > href="img/favicon.ico?_=5.3.0"> > > > > > > > > > > <link rel="stylesheet" type="text/css" > > > > > href="css/styles/common.css?_=5.3.0"> > > > > > <link rel="stylesheet" type="text/css" > > > > > href="css/styles/analysis.css?_=5.3.0"> > > > > > <link rel="stylesheet" type="text/css" > > > > > href="css/styles/cloud.css?_=5.3.0"> > > > > > <link rel="stylesheet" type="text/css" > > > > > href="css/styles/cores.css?_=5.3.0"> > > > > > <link rel="stylesheet" type="text/css" > > > > > href="css/styles/dashboard.css?_=5.3.0"> > > > > > <link rel="stylesheet" type="text/css" > > > > > href="css/styles/dataimport.css?_=5.3.0"> > > > > > <link rel="stylesheet" type="text/css" > > > > > href="css/styles/files.css?_=5.3.0"> > > > > > <link rel="stylesheet" type="text/css" > > > > > href="css/styles/index.css?_=5.3.0"> > > > > > <link rel="stylesheet" type="text/css" > > > > > href="css/styles/java-properties.css?_=5.3.0"> > > > > > <link rel="stylesheet" type="text/css" > > > > > href="css/styles/logging.css?_=5.3.0"> > > > > > <link rel="stylesheet" type="text/css" > > > > > href="css/styles/menu.css?_=5.3.0"> > > > > > <link rel="stylesheet" type="text/css" > > > > > href="css/styles/plugins.css?_=5.3.0"> > > > > > <link rel="stylesheet" type="text/css" > > > > > href="css/styles/documents.css?_=5.3.0"> > > > > > <link rel="stylesheet" type="text/css" > > > > > href="css/styles/query.css?_=5.3.0"> > > > > > <link rel="stylesheet" type="text/css" > > > > > href="css/styles/replication.css?_=5.3.0"> > > > > > <link rel="stylesheet" type="text/css" > > > > > href="css/styles/schema-browser.css?_=5.3.0"> > > > > > <link rel="stylesheet" type="text/css" > > > > > href="css/styles/threads.css?_=5.3.0"> > > > > > <link rel="stylesheet" type="text/css" > > > > > href="css/styles/segments.css?_=5.3.0"> > > > > > <link rel="stylesheet" type="text/css" > href="css/chosen.css?_=5.3.0"> > > > > > > > > > > <meta http-equiv="x-ua-compatible" content="IE=9"> > > > > > > > > > > <script type="text/javascript"> > > > > > > > > > > var app_config = {}; > > > > > > > > > > app_config.solr_path = '\/solr'; > > > > > app_config.core_admin_path = '\/admin\/cores'; > > > > > > > > > > </script> > > > > > > > > > > </head> > > > > > <body> > > > > > > > > > > <div id="wrapper"> > > > > > > > > > > <div id="header"> > > > > > > > > > > <a href="./" id="solr"><span>Apache SOLR</span></a> > > > > > > > > > > <p id="environment"> </p> > > > > > > > > > > </div> > > > > > > > > > > <div id="main" class="clearfix"> > > > > > > > > > > <div id="init-failures"> > > > > > > > > > > <h2>SolrCore Initialization Failures</h2> > > > > > <ul></ul> > > > > > <p>Please check your logs for more information</p> > > > > > > > > > > </div> > > > > > > > > > > <div id="content-wrapper"> > > > > > <div id="content"> > > > > > > > > > > > > > > > > > > > > </div> > > > > > </div> > > > > > > > > > > <div id="menu-wrapper"> > > > > > <div> > > > > > > > > > > <ul id="menu"> > > > > > > > > > > <li id="index" class="global"><p><a > > > > > href="#/">Dashboard</a></p></li> > > > > > > > > > > <li id="logging" class="global"><p><a > > > > > href="#/~logging">Logging</a></p> > > > > > <ul> > > > > > <li class="level"><a > > > href="#/~logging/level">Level</a></li> > > > > > </ul> > > > > > </li> > > > > > > > > > > <li id="cloud" class="global optional"><p><a > > > > > href="#/~cloud">Cloud</a></p> > > > > > <ul> > > > > > <li class="tree"><a > > > href="#/~cloud?view=tree">Tree</a></li> > > > > > <li class="graph"><a href="#/~cloud">Graph</a></li> > > > > > <li class="rgraph"><a > href="#/~cloud?view=rgraph">Graph > > > > > (Radial)</a></li> > > > > > <li class="dump"><a href="#/~cloud">Dump</a></li> > > > > > </ul> > > > > > </li> > > > > > > > > > > <li id="cores" class="global"><p><a > href="#/~cores">Core > > > > > Admin</a></p></li> > > > > > > > > > > <li id="java-properties" class="global"><p><a > > > > > href="#/~java-properties">Java Properties</a></li> > > > > > > > > > > <li id="threads" class="global"><p><a > > > href="#/~threads">Thread > > > > > Dump</a></p></li> > > > > > > > > > > </ul> > > > > > > > > > > <div id="core-selector"> > > > > > <div id="has-cores"> > > > > > <select data-placeholder="Core Selector"></select> > > > > > </div> > > > > > <p id="has-no-cores"><a href="#/~cores"> > > > > > No cores available > > > > > <span>Go and create one</span> > > > > > </a></p> > > > > > </div> > > > > > <div id="core-menu"> > > > > > <ul></ul> > > > > > </div> > > > > > > > > > > </div> > > > > > </div> > > > > > > > > > > <div id="meta"> > > > > > > > > > > <ul> > > > > > > > > > > <li class="documentation"><a href=" > > > > > http://lucene.apache.org/solr/ > > > > > "><span>Documentation</span></a></li> > > > > > <li class="issues"><a href=" > > > > > http://issues.apache.org/jira/browse/SOLR"><span>Issue > > > > > Tracker</span></a></li> > > > > > <li class="irc"><a > > > > > href="https://wiki.apache.org/solr/IRCChannels"><span>IRC > > > > > Channel</span></a></li> > > > > > <li class="mailinglist"><a href=" > > > > > http://lucene.apache.org/solr/resources.html#community > > > "><span>Community > > > > > forum</span></a></li> > > > > > <li class="wiki-query-syntax"><a href=" > > > > > > > > > https://cwiki.apache.org/confluence/display/solr/Query+Syntax+and+Parsing > > > > > "><span>Solr > > > > > Query Syntax</span></a></li> > > > > > > > > > > </ul> > > > > > > > > > > </div> > > > > > > > > > > </div> > > > > > > > > > > </div> > > > > > > > > > > <div id="connection_status"> > > > > > > > > > > <span>Connection lost …</span> > > > > > > > > > > </div> > > > > > > > > > > <script type="text/javascript"> var require = { urlArgs: > '_=5.3.0' }; > > > > > </script> > > > > > <script src="js/require.js?_=5.3.0" data-main="js/main"></script> > > > > > > > > > > </body> > > > > > </html> > > > > > > > > > > > > > > > On Thu, Sep 3, 2015 at 4:12 PM, Upayavira <u...@odoko.co.uk> wrote: > > > > > > > > > > > > > > > > > > > > > > > On Thu, Sep 3, 2015, at 11:19 AM, Ritesh Sinha wrote: > > > > > > > I am learning solr and want to use solr for stemming > words.I'll be > > > > > > > passing > > > > > > > the word to the solr and it should send the stemmed word back.I > > > know > > > > > how > > > > > > > to > > > > > > > configure solr core for different stemming patterns and also i > am > > > able > > > > > to > > > > > > > view their stemmed words in the analyzer (solr admin ui) but i > am > > > not > > > > > > > sure > > > > > > > how to achieve this using java code.I am able to index and > query > > > using > > > > > > > java > > > > > > > api. > > > > > > > > > > > > Use your browser's "developer tools" to see what is going on > behind > > > the > > > > > > scenes when you use the admin UI analysis tab. > > > > > > > > > > > > It is just an HTTP call that you can replicate from Java. I see > that > > > > > > SolrJ has a FieldAnalysisRequest that I suspect does the very > same > > > > > > thing. > > > > > > > > > > > > Hope that helps. > > > > > > > > > > > > Upayavira > > > > > > > > > > > > > > >