You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Paul Tomblin <pt...@xcski.com> on 2009/08/17 23:11:38 UTC
SolrJ question
If I put an object into a SolrInputDocument and store it, how do I
query for it back? For instance, I stored a java.net.URI in a field
called "url", and I want to query for all the documents that match a
particular URI. The query syntax only seems to allow Strings, and if
I just try query.setQuery("url:" + uri.toString()) I get an error
because of the colon after "http" in the URI.
I'm really new to Solr, so please let me know if I'm missing something
basic here.
--
http://www.linkedin.com/in/paultomblin
Re: SolrJ question
Posted by Paul Tomblin <pt...@xcski.com>.
On Mon, Aug 17, 2009 at 5:47 PM, Paul Tomblin<pt...@xcski.com> wrote:
> Hmmm. It's not working right. I've added a 5 documents, 3 with the
> URL set to "http://xcski.com/pharma/" and 2 with the URL set to
> "http://xcski.com/nano/". Doing other sorts of queries seems to be
> pulling back the right data:
Of course, It doesn't help that my url field was set to
indexed="false" in the schema. Changing it to true fixed it.
--
http://www.linkedin.com/in/paultomblin
Re: SolrJ question
Posted by Paul Tomblin <pt...@xcski.com>.
On Mon, Aug 17, 2009 at 5:36 PM, Ensdorf Ken<En...@zoominfo.com> wrote:
>> Does this mean I should have converted my objects to string before
>> writing them to the server?
>>
>
> I believe SolrJ takes care of that for you by calling toString(), but you would need to convert explicitly when you query (and then escape).
>
Hmmm. It's not working right. I've added a 5 documents, 3 with the
URL set to "http://xcski.com/pharma/" and 2 with the URL set to
"http://xcski.com/nano/". Doing other sorts of queries seems to be
pulling back the right data:
[DEBUG] 34:20 (Solr.java:getForConcept:116)
[java] search term = fribbet, concept = pharma
[java]
[java] Aug 17, 2009 5:34:20 PM org.apache.solr.core.SolrCore execute
[java] INFO: [] webapp=null path=/select
params={q=fribbet&fq=concept%3Apharma} hits=1 status=0 QTime=9
[java] [DEBUG] 34:20 (Solr.java:getForConcept:130)
[java] got doc SolrDocument[{id=2:http://xcski.com/pharma/,
concept=pharma, text=this is a third big long chunk of text containing
the word fribbet, title=this is the third title, keywords=pills,drugs,
origDoctype=html, chunkNum=2, url=http://xcski.com/pharma/}]
But if I want to restrict it to a specific URL, I use
SolrQuery query = new SolrQuery();
query.setQuery("url:" + ClientUtils.escapeQueryChars(url));
and it's not returning anything. Log4j output looks like:
[java] [DEBUG] 34:20 (Solr.java:getAllForURL:89)
[java] getting for URL: http://xcski.com/nano/
[java]
[java] Aug 17, 2009 5:34:20 PM org.apache.solr.core.SolrCore execute
[java] INFO: [] webapp=null path=/select
params={q=url%3Ahttp%5C%3A%5C%2F%5C%2Fxcski%5C.com%5C%2Fnano%5C%2F}
hits=0 status=0 QTime=16
[java] [DEBUG] 34:20 (Solr.java:main:229)
[java] found: 0
Actually, looking at that, it looks like it's escaped the URL twice,
converting ":" into "%3A", then converting that to "%5C%3A". Could
that be?
--
http://www.linkedin.com/in/paultomblin
RE: SolrJ question
Posted by Ensdorf Ken <En...@zoominfo.com>.
> Does this mean I should have converted my objects to string before
> writing them to the server?
>
I believe SolrJ takes care of that for you by calling toString(), but you would need to convert explicitly when you query (and then escape).
Re: SolrJ question
Posted by Paul Tomblin <pt...@xcski.com>.
On Mon, Aug 17, 2009 at 5:30 PM, Ensdorf Ken<En...@zoominfo.com> wrote:
> You can escape the string with
>
> org.apache.lucene.queryParser.QueryParser.escape(String query)
>
> http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/queryParser/QueryParser.html#escape%28java.lang.String%29
>
Does this mean I should have converted my objects to string before
writing them to the server?
--
http://www.linkedin.com/in/paultomblin
RE: SolrJ question
Posted by Ensdorf Ken <En...@zoominfo.com>.
You can escape the string with
org.apache.lucene.queryParser.QueryParser.escape(String query)
http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/queryParser/QueryParser.html#escape%28java.lang.String%29
> -----Original Message-----
> From: ptomblin@gmail.com [mailto:ptomblin@gmail.com] On Behalf Of Paul
> Tomblin
> Sent: Monday, August 17, 2009 5:12 PM
> To: solr-user@lucene.apache.org
> Subject: SolrJ question
>
> If I put an object into a SolrInputDocument and store it, how do I
> query for it back? For instance, I stored a java.net.URI in a field
> called "url", and I want to query for all the documents that match a
> particular URI. The query syntax only seems to allow Strings, and if
> I just try query.setQuery("url:" + uri.toString()) I get an error
> because of the colon after "http" in the URI.
>
> I'm really new to Solr, so please let me know if I'm missing something
> basic here.
>
> --
> http://www.linkedin.com/in/paultomblin
Re: SolrJ question
Posted by Paul Tomblin <pt...@xcski.com>.
On Mon, Aug 17, 2009 at 5:28 PM, Harsch, Timothy J. (ARC-SC)[PEROT
SYSTEMS]<ti...@nasa.gov> wrote:
> Assuming you have written the SolrInputDocument to the server, you would next query.
I'm sorry, I don't understand what you mean by "you would next query."
There appear to be some words missing from that sentence.
--
http://www.linkedin.com/in/paultomblin
RE: SolrJ question
Posted by "Harsch, Timothy J. (ARC-SC)[PEROT SYSTEMS]" <ti...@nasa.gov>.
Assuming you have written the SolrInputDocument to the server, you would next query. See ClientUtils.escapeQueryChars. Also you need to be cognizant of URLEncoding at times.
-----Original Message-----
From: ptomblin@gmail.com [mailto:ptomblin@gmail.com] On Behalf Of Paul Tomblin
Sent: Monday, August 17, 2009 2:12 PM
To: solr-user@lucene.apache.org
Subject: SolrJ question
If I put an object into a SolrInputDocument and store it, how do I
query for it back? For instance, I stored a java.net.URI in a field
called "url", and I want to query for all the documents that match a
particular URI. The query syntax only seems to allow Strings, and if
I just try query.setQuery("url:" + uri.toString()) I get an error
because of the colon after "http" in the URI.
I'm really new to Solr, so please let me know if I'm missing something
basic here.
--
http://www.linkedin.com/in/paultomblin