deleteById always returning OK
Is it expected behaviour that "deleteById" will always return OK as a status, regardless of whether the id was matched? I have a unit test: // set up the test data engine.index(12345, s1, d1); engine.index(54321, s2, d2); engine.index(23453, s3, d3); // ... @Test public void testRemove() throws Exception { assertEquals(engine.size(), 3); assertTrue(engine.remove(12345)); assertEquals(engine.size(), 2); // XXX, it returns true assertFalse(engine.remove(23523352)); "Engine" is my wrapper around Solr. The remove method looks like this: private static final int RESPONSE_STATUS_OK = 0; private SolrServer server; public boolean remove(final Integer titleInstanceId) throws IOException { try { server.deleteById(String.valueOf(titleInstanceId)); final UpdateResponse updateResponse = server.commit(true, true); // XXX It's always OK return (updateResponse.getStatus() == RESPONSE_STATUS_OK); Any ideas what's going wrong? Is there a different way to test for the id not having been there, other than an additional search? Thanks Reuben
Attempt to query for max id failing with exception
I'm using SolrJ. When I attempt to set up a query to retrieve the maximum id in the index, I'm getting an exception. My setup code is: final SolrQuery params = new SolrQuery(); params.addSortField("id", ORDER.desc); params.setRows(1); params.setQuery(queryString); final QueryResponse queryResponse = server.query(params); This latter line is blowing up with: Not Found request: http://solr.xxx.myserver/select?sort=iddesc&rows=1&q=*:*&wt=javabin&version=2.2 org.apache.solr.common.SolrException org.apache.solr.client.solrj.impl.CommonsHttpSolrServer#request(343) org.apache.solr.client.solrj.impl.CommonsHttpSolrServer#request(183) org.apache.solr.client.solrj.request.QueryRequest#process(90) org.apache.solr.client.solrj.SolrServer#query(109) There are a couple things to note - - there is a space between id and desc which looks suspicious, but swapping changing wt to XML and leaving the URL otherwise the same causes solr no grief when queried via a browser - the index is in fact empty - this particular section of code is bulk loading our documents, and using the max id query to figure out where to start from. (I can and will try catching the exception and assuming 0, but ideally I wouldn't get an exception just from doing the query) Am I doing this query in the wrong way? Thanks Reuben
Re: Attempt to query for max id failing with exception
Yep, thanks - this turned out to be a systems configuration error. Our sysadmin hadn't opened up the http port on the server's internal network interface; I could browse to it from outside (i.e. firefox on my machine), but the apache landing page was being returned when CommonsHttpSolrServer tried to get at it. Reuben On Fri, Aug 7, 2009 at 12:03 PM, Yonik Seeley wrote: > I just tried this sample code... it worked fine for me on trunk. > > -Yonik > http://www.lucidimagination.com > > On Thu, Aug 6, 2009 at 8:28 PM, Reuben Firmin wrote: > > I'm using SolrJ. When I attempt to set up a query to retrieve the maximum > id > > in the index, I'm getting an exception. > > > > My setup code is: > > > > final SolrQuery params = new SolrQuery(); > > params.addSortField("id", ORDER.desc); > > params.setRows(1); > > params.setQuery(queryString); > > > > final QueryResponse queryResponse = server.query(params); > > > > This latter line is blowing up with: > > > > Not Found > > > > request: > http://solr.xxx.myserver/select?sort=iddesc&rows=1&q=*:*&wt=javabin&version=2.2 > > org.apache.solr.common.SolrException > > org.apache.solr.client.solrj.impl.CommonsHttpSolrServer#request(343) > > > org.apache.solr.client.solrj.impl.CommonsHttpSolrServer#request(183) > >org.apache.solr.client.solrj.request.QueryRequest#process(90) > >org.apache.solr.client.solrj.SolrServer#query(109) > > > > There are a couple things to note - > > > > - there is a space between id and desc which looks suspicious, but > > swapping changing wt to XML and leaving the URL otherwise the same > causes > > solr no grief when queried via a browser > > - the index is in fact empty - this particular section of code is bulk > > loading our documents, and using the max id query to figure out where > to > > start from. (I can and will try catching the exception and assuming 0, > but > > ideally I wouldn't get an exception just from doing the query) > > > > Am I doing this query in the wrong way? > > > > Thanks > > Reuben > > >
PhoneticFilterFactory related questions
Hi, I have a schema with three (relevant to this question) fields: title, author, book_content. I found that if PhoneticFilterFactory is used as a filter on book_content, it was bringing back all kinds of unrelated results, so I have it applied only against title and author. Questions -- 1) I have the filter set up on both the index and query analyzers for the fieldType of title/author. When running against an index which had been built without the phonetic filter, phonetic searches still worked. Is there a performance benefit to applying the phonetic filter to the index analyzer as well as the query analyzer, are there other benefits to doing so, or should I not bother? (I.e. should I just apply the filter to the query analyzer?) 2) Title / author matches are generally boosted, which is fine if it's an exact match (i.e. "Shakespeare In Love" or "by William Shakespeare" are more relevant than a book which mentions Shakespeare). However, the phonetic filter put a bit of a spanner in the works - now if I search for "bottling", books with the word "b*a*ttling" in the title show up above books with the non-substituted word in the content. How can I juggle the boosting / field setup to be something like: a) Title/author matches (with exactly matched spelling - stemming etc is fine) b) Content matches (with exactly matched spelling) c) Title/author matches (with phoneme equivalent spelling) Do I need to create separate non-phonetic title/author fields for this, or is there a different way to achieve the same effect? Thanks Reuben
Trying to run embedded server from unit test...but getting configuration error
Hi, I'm setting up an embedded solr server from a unit test (the non-bolded lines are just moving test resources to a tmp directory which is acting as solor.home.) final File dir = FileUtils.createTmpSubdir(); *System.setProperty("solr.solr.home", dir.getAbsolutePath());* final File conf = new File(dir, "conf"); conf.mkdir(); final PathMatchingResourcePatternResolver pmrpr = new PathMatchingResourcePatternResolver(); final File c1 = pmrpr.getResource("classpath:schema.xml").getFile(); final File c2 = pmrpr.getResource("classpath:solrconfig.xml").getFile(); final File c3 = pmrpr.getResource("classpath:test_protwords.txt").getFile(); final File c4 = pmrpr.getResource("classpath:test_stopwords.txt").getFile(); final File c5 = pmrpr.getResource("classpath:test_synonyms.txt").getFile(); FileUtils.copyFileToDirectory(c1, conf); // NOTE! this lives in the top level dir FileUtils.copyFileToDirectory(c2, dir); copyAndRenameTestFile(c3, dir, "protwords.txt", conf); copyAndRenameTestFile(c4, dir, "stopwords.txt", conf); copyAndRenameTestFile(c5, dir, "synonyms.txt", conf); *final CoreContainer.Initializer initializer = new CoreContainer.Initializer(); initializer.setSolrConfigFilename("solrconfig.xml"); final CoreContainer coreContainer = initializer.initialize(); final EmbeddedSolrServer server = new EmbeddedSolrServer(coreContainer, ""); engine.setServer(server);* The problem with this is that CoreContainer trips over and dumps an exception to the log: javax.xml.transform.TransformerException: Unable to evaluate expression using this context at com.sun.org.apache.xpath.internal.XPath.execute(XPath.java:363) at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.eval(XPathImpl.java:213) at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.java:275) at org.apache.solr.core.CoreContainer.readProperties(CoreContainer.java:241) at org.apache.solr.core.CoreContainer.load(CoreContainer.java:189) at org.apache.solr.core.CoreContainer$Initializer.initialize(CoreContainer.java:104) at org.bookshare.search.solr.SolrSearchEngineTest.setup(SolrSearchEngineTest.java:44) It appears to be trying to evaluate "property", which doesn't exist in solrconfig.xml (which is pretty much the same as http://svn.apache.org/repos/asf/lucene/solr/trunk/example/solr/conf/solrconfig.xml). Anybody see anything obviously wrong? If not, what else can I give you to help debug this? Thanks Reuben
Re: Trying to run embedded server from unit test...but getting configuration error
Thanks. I should have googled first. I came across: http://www.nabble.com/EmbeddedSolrServer-API-usage-td19778623.html For reference, my code is now: final File dir = FileUtils.createTmpSubdir(); System.setProperty("solr.solr.home", dir.getAbsolutePath()); final File conf = new File(dir, "conf"); conf.mkdir(); final PathMatchingResourcePatternResolver pmrpr = new PathMatchingResourcePatternResolver(); final File c1 = pmrpr.getResource("classpath:test_protwords.txt").getFile(); final File c2 = pmrpr.getResource("classpath:test_stopwords.txt").getFile(); final File c3 = pmrpr.getResource("classpath:test_synonyms.txt").getFile(); final File c4 = pmrpr.getResource("classpath:test_elevate.xml").getFile(); copyAndRenameTestFile(c1, dir, "protwords.txt", conf); copyAndRenameTestFile(c2, dir, "stopwords.txt", conf); copyAndRenameTestFile(c3, dir, "synonyms.txt", conf); copyAndRenameTestFile(c4, dir, "elevate.xml", conf); final File config = pmrpr.getResource("classpath:solrconfig.xml").getFile(); final CoreContainer cc = new CoreContainer(); final SolrConfig sc = new SolrConfig(config.getAbsolutePath()); final CoreDescriptor cd = new CoreDescriptor(cc, "core0", dir.getAbsolutePath()); final SolrCore core0 = cc.create(cd); cc.register("core0", core0, false); final EmbeddedSolrServer server = new EmbeddedSolrServer(cc, "core0"); Reuben On Mon, Jul 13, 2009 at 5:00 PM, Mark Miller wrote: > I believe that constructor expects to find an alternate format solr config > that specifies the cores, eg like the one you can find in > example/multicore/solr.xml > > http://svn.apache.org/repos/asf/lucene/solr/trunk/example/multicore/solr.xml > > Looks like that error is not finding the root solr node, so likely your > trying to use a regular solrconfig.xml format? > > -- > -- > - Mark > > http://www.lucidimagination.com > > On Mon, Jul 13, 2009 at 8:53 PM, Reuben Firmin > wrote: > > > Hi, > > > > I'm setting up an embedded solr server from a unit test (the non-bolded > > lines are just moving test resources to a tmp directory which is acting > as > > solor.home.) > > > >final File dir = FileUtils.createTmpSubdir(); > > *System.setProperty("solr.solr.home", dir.getAbsolutePath());* > >final File conf = new File(dir, "conf"); > >conf.mkdir(); > >final PathMatchingResourcePatternResolver pmrpr = new > > PathMatchingResourcePatternResolver(); > >final File c1 = > pmrpr.getResource("classpath:schema.xml").getFile(); > >final File c2 = > > pmrpr.getResource("classpath:solrconfig.xml").getFile(); > >final File c3 = > > pmrpr.getResource("classpath:test_protwords.txt").getFile(); > >final File c4 = > > pmrpr.getResource("classpath:test_stopwords.txt").getFile(); > >final File c5 = > > pmrpr.getResource("classpath:test_synonyms.txt").getFile(); > >FileUtils.copyFileToDirectory(c1, conf); > >// NOTE! this lives in the top level dir > >FileUtils.copyFileToDirectory(c2, dir); > >copyAndRenameTestFile(c3, dir, "protwords.txt", conf); > >copyAndRenameTestFile(c4, dir, "stopwords.txt", conf); > >copyAndRenameTestFile(c5, dir, "synonyms.txt", conf); > > > > *final CoreContainer.Initializer initializer = new > > CoreContainer.Initializer(); > >initializer.setSolrConfigFilename("solrconfig.xml"); > >final CoreContainer coreContainer = initializer.initialize(); > >final EmbeddedSolrServer server = new > > EmbeddedSolrServer(coreContainer, ""); > >engine.setServer(server);* > > > > The problem with this is that CoreContainer trips over and dumps an > > exception to the log: > > > > javax.xml.transform.TransformerException: Unable to evaluate expression > > using this context > >at com.sun.org.apache.xpath.internal.XPath.execute(XPath.java:363) > >at > > com.sun.org.apache.xpath.internal.jaxp.XPathImpl.eval(XPathImpl.java:213) > >at > > > > > com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.java:275) > >at > > org.apache.solr.core.CoreContainer.readProperties(CoreContainer.java:241) > >at org.apache.solr.core.CoreContainer.load(CoreContainer.java:189) > >at > > > > > org.apache.solr.core.CoreContainer$Initializer.initialize(CoreContainer.java:104) > >at > > > > > org.bookshare.search.solr.SolrSearchEngineTest.setup(SolrSearchEngineTest.java:44) > > > > It appears to be trying to evaluate "property", which doesn't exist in > > solrconfig.xml (which is pretty much the same as > > > > > http://svn.apache.org/repos/asf/lucene/solr/trunk/example/solr/conf/solrconfig.xml > > ). > > > > > > Anybody see anything obviously wrong? If not, what else can I give you to > > help debug this? > > > > Thanks > > Reuben > > >
Guide to using SolrQuery object
Hi, It seems that SolrQuery is a better API than the basic ModifiableSolrParams, but I can't make it work. Constructing params with: final ModifiableSolrParams params = new ModifiableSolrParams(); params.set("q", queryString); ...results in a successful search. Constructing SolrQuery with: final SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery(queryString); ... doesn't (with the same unit test driving the search). I'm sure I'm missing some basic option, but the javadoc is a little terse, and I don't see what I'm missing. Ideas? Also, are there enums or constants around the various param names that can be passed in, or do people tend to define those themselves? Thanks! Reuben