treygrainger / solr-in-action Goto Github PK
View Code? Open in Web Editor NEWSample code, data, and configuration for the book
Home Page: http://solrinaction.com
License: Apache License 2.0
Sample code, data, and configuration for the book
Home Page: http://solrinaction.com
License: Apache License 2.0
================================================================================ Solr in Action Example Code ================================================================================ Thank you for purchasing Solr in Action! Here are some basic instructions on running the example code provided in the book. 1. Directory layout $SOLR_IN_ACTION/ - this is the location where you pulled or extracted the code | |__src/ | |__main/ | |__java/ - contains all the Java source files from examples in the book | |__example-docs/ - contains example config and content files for each chapter | |__scripts/ - contains scripts for separately executing each chapter's examples | |__pom.xml - maven build file | |__README.txt - you're looking at it ;-) | |__LICENSE - Open Source License (Apache 2.0) | |__NOTICE - Description of project dependencies | |__chapter-examples.sh - script to conveniently execute all examples in the book | |__solr-in-action.jar - compiled source code (follow step 2 to build this file) 2. Building the source code You'll need Maven to build the source code. If you need some help on getting Maven setup and running, please see: Maven in Five Minutes http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html Once you have Maven setup, cd into the directory where you extracted the example source code zip file and do: mvn clean package This will compile the source code and build an executable JAR file in the main directory ($SOLR_IN_ACTION) named: solr-in-action.jar 3. Several chapters include executable code examples. To make these easy to run, we built a simple driver application that allows you to just pass in the name of the example you want to run and it will figure it out. To run a specific example from the book, use the java -jar command to launch the executable JAR you built in step 2 above. For example, to run the ExampleSolrJClient application from Chapter 5, do: java -jar solr-in-action.jar ch5.ExampleSolrJClient In most cases, you can just pass the example class name without the package information and the driver will figure it out, i.e. java -jar solr-in-action.jar examplesolrjclient The driver will figure out that you're trying to run example class: sia.ch5.ExampleSolrJClient To see a list of all available examples, simply do: java -jar solr-in-action.jar To see a list of all examples for a specific chapter, pass the chapter number, e.g. the following command will show all examples for chapter 5: java -jar solr-in-action.jar 5 4. The book is filled with code listings, many of which demonstrate the HTTP request syntax for executing specific types of Solr queries. You can type these URLs into you favorite web browser, or you can alternatively just pass the listing number into the included http utility to execute the request. e.g. the following command will execute the request demonstrated in listing 2.1: java -jar solr-in-action.jar listing 2.1 Enjoy! ================================================================================
I have included jar files into solr(6.2.0) lib folders. It is giving me error:
Caused by: java.lang.ClassCastException: class org.apache.lucene.codecs.pulsing.Pulsing41PostingsFormat
at java.lang.Class.asSubclass(Unknown Source)
at org.apache.lucene.util.SPIClassIterator.next(SPIClassIterator.java:158)
at org.apache.lucene.util.NamedSPILoader.reload(NamedSPILoader.java:70)
at org.apache.lucene.util.NamedSPILoader.(NamedSPILoader.java:51)
at org.apache.lucene.util.NamedSPILoader.(NamedSPILoader.java:38)
at org.apache.lucene.codecs.PostingsFormat$Holder.(PostingsFormat.java:49)
... 14 more
I've noticed that if I use the provided PatternReplaceCharFilterFactory config in chapter 6, then input strings aren't properly tokenized.
For example:
<!-- other config -->
<fieldType name="text_microblog" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<charFilter class="solr.PatternReplaceCharFilterFactory"
pattern="([a-zA-Z])\1+"
replacement="$1$1"/>
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.WordDelimiterFilterFactory"
<!-- other config -->
with the request: http://localhost:8983/solr/#/example_collection/analysis?analysis.fieldvalue=1%202&analysis.fieldtype=text_microblog&verbose_output=1. In the response, SOLR does not properly tokenize the string "1 2" to a collection of characters "1" and "2". This is not how it is described in the book.
If I remove the PatternReplaceCharFilterFactory like so:
<!-- other config -->
<fieldType name="text_microblog" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.WordDelimiterFilterFactory"
<!-- other config -->
and reboot the SOLR instance, the query above produces the correct response where the string "1 2" is properly recognized as two characters "1" and "2".
Is this expected?
At the end of method
addTokenStreamForFieldType
proper handling of tokenStream must be added:
tokenStream.end();
tokenStream.close();
In solr 4.6.0 it breaks.
When trying to use this in SolrCloud 5.2.1, it did not work. It appears there may have been some changes to the SolrJ classes or the hierarchy of information in clusterstate.json. When retrieving the slice in Solr 5.2.1, it gets the shard and therefore the code is checking the shard state instead of a specific replica within the shard. In order to get the specific replica state we need to get the replica from the shard using the CloudDescriptor's nodeName.
Replace:
replicaState = (slice != null) ? slice.getState() : "gone";
with:
if ( slice != null ) {
Replica thisReplica = slice.getReplica(cloud.getCoreNodeName());
replicaState = (thisReplica != null) ? thisReplica.getState().toString() : "gone";
}
else {
replicaState = "gone";
}
After making the above change, I was seeing the correct state when hitting the admin/ping request handler when the replica was not active.
<lst name="error">
<str name="msg">Replica at 192.168.1.100:8984_solr for shard2 in the xyz collection is not active! State is: recovering</str>
...
</str><str name="trace">
<int name="code">500</int>
</list>
Hi,
I have a custom function query and also made solr recognize it by adding the class name in solr.xml. Even though solr loads the class it does not execute it and gives an error saying
"solr cannot determine sort order".
Could you help me out in knowing if the error was caused in the custom function query as the error does not point to the location of the class named after custom function query.(OR) did I do any wrong in creating a jar for the custom query function as I could have misunderstood how the jar should be so that solr can execute it. I created the jar without including the depedencies as, if I include the depedencies I get Manifest error. I used maven in writing the implementation for ValuseSource class and ValueSourceParser.
The error that appears in solr is as follows::
org.apache.solr.common.SolrException: Can't determine a Sort Order (asc or desc) in sort spec 'CustomRanking(feild1,feild2,someString) desc', pos=58
at org.apache.solr.search.QueryParsing.parseSortSpec(QueryParsing.java:340)
at org.apache.solr.search.QParser.getSort(QParser.java:247)
at org.apache.solr.handler.component.QueryComponent.prepare(QueryComponent.java:175)
at org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:197)
at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:135)
at org.apache.solr.core.SolrCore.execute(SolrCore.java:1967)
at org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:777)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:418)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:207)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:455)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1075)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:368)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
at org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:53)
at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:942)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1004)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:640)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:72)
at org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:264)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Thread.java:745)
Regards,
Aditya Reddy.
Hi, very good book, thank you very much.
I have a bug when I try to run the example on chapter 14.
I did not get any trouble until then.
root@26d2788a65e0:/code# cd $SOLR_INSTALL/example/
root@26d2788a65e0:/opt/solr/example# cp -r $SOLR_IN_ACTION/example-docs/ch14/cores/* solr/
root@26d2788a65e0:/opt/solr/example# cp $SOLR_IN_ACTION/solr-in-action.jar solr/lib/
root@26d2788a65e0:/opt/solr/example# java -jar start.jar
0 [main] INFO org.eclipse.jetty.server.Server – jetty-8.1.10.v20130312
32 [main] INFO org.eclipse.jetty.deploy.providers.ScanningAppProvider – Deployment monitor /opt/solr-4.10.4/example/contexts at interval 0
36 [main] INFO org.eclipse.jetty.deploy.DeploymentManager – Deployable added: /opt/solr-4.10.4/example/contexts/solr-jetty-context.xml
1020 [main] INFO org.eclipse.jetty.webapp.StandardDescriptorProcessor – NO JSP Support for /solr, did not find org.apache.jasper.servlet.JspServlet
1100 [main] INFO org.apache.solr.servlet.SolrDispatchFilter – SolrDispatchFilter.init()
1139 [main] INFO org.apache.solr.core.SolrResourceLoader – JNDI not configured for solr (NoInitialContextEx)
1140 [main] INFO org.apache.solr.core.SolrResourceLoader – solr home defaulted to 'solr/' (could not find system property or JNDI)
1141 [main] INFO org.apache.solr.core.SolrResourceLoader – new SolrResourceLoader for directory: 'solr/'
1142 [main] INFO org.apache.solr.core.SolrResourceLoader – Adding 'file:/opt/solr-4.10.4/example/solr/lib/.DS_Store' to classloader
1143 [main] INFO org.apache.solr.core.SolrResourceLoader – Adding 'file:/opt/solr-4.10.4/example/solr/lib/solr-in-action.jar' to classloader
1146 [main] INFO org.apache.solr.core.SolrResourceLoader – Adding 'file:/opt/solr-4.10.4/example/solr/lib/.emptydir' to classloader
1232 [main] ERROR org.apache.solr.servlet.SolrDispatchFilter – Could not start Solr. Check solr/home property and the logs
1257 [main] ERROR org.apache.solr.core.SolrCore – null:java.lang.IllegalAccessError: class org.apache.lucene.codecs.diskdv.DiskDocValuesProducer cannot access its superclass org.apache.lucene.codecs.lucene45.Lucene45DocValuesProducer
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
The problem comes from the compiled solr-in-action.jar that is placed under solr/lib and failed the startup of solr.
I tried removing all the newly added cores of the ch14 and the problem persist.
Only when I remove the solr/lib/solr-in-action.jar that the error disappear.
The pom.xml is configured to be self contained using the maven-assembly-plugin but it seems to have a problem.
Can you please help me debug this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.