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 Thanh Doan <tc...@gmail.com> on 2009/06/07 03:52:50 UTC

Re: Facet query return zero hits if category facet value has 2 or more words (looks like space does not work)

Hi Steve,

No. My cat2_facet field does not have id number. In the 2 queries  below...
not sure why query 1 did not work and query 2 worked perfectly.

1) query 1 (should return 2 documents, but it did not work)

webapp=/solr path=/select
params={facet=true&fl=pk_i,score&facet.mincount=1&q=([*+TO+*]+AND+*
cat2_facet:Top+Wear*)+AND+(type_s:Item)&facet.limit=-1&facet.field=cat1_facet&facet.field=cat2_facet&qt=standard&wt=ruby}
*hits=0* status=0 QTime=10

2) query 2 (worked. did return 2 documents)
webapp=/solr path=/select params={facet=true&fl=pk_i,
score&facet.mincount=1&q=([*+TO+*]+AND+*cat2_facet:Shoes*)+AND+(type_s:Item)&facet.limit=-1&facet.field=cat1_facet&facet.field=cat2_facet&qt=standard&wt=ruby}
*hits=2* status=0 QTime=1

Have you ever used a string facet field in which the facet value contains 2
or more words like
Brand:Hewlett Packard

If yes, what the query looks like exactly to filter the results based on the
facet value = 'Hewlett Packard'?

Thanks.
Thanh

On Fri, Jun 5, 2009 at 10:09 PM, Stephen Weiss <sw...@stylesight.com>wrote:

> Thanh,
>
> Do the categories have id numbers?   What we do is we index the ID numbers
> of our tags and categories, and then on display we pull the real text out of
> the database.  In our situation, since the tags and categories are
> multilingual, it's a lot easier than converting from English to the other
> language where conflicts in encoding can arise.  The advantage is, the id
> number never has a space or any special character, so it always works.
>
> Another quick and dirty option might be to index the field as type "string"
> - but then you probably want to do this with a copyField since it'll make it
> more cumbersome to search through with a text query.  I haven't tried this
> though so I'm not sure.
>
> --
> Steve
>
>
> On Jun 5, 2009, at 9:00 PM, Thanh Doan wrote:
>
>  I used latest acts_as_solr   to index a number of sample  'sale' items.
>> Those item documents has a facet field, Its name is cat2_facet.
>>
>> There are a number of documents that have cat2_facet= "Shoes" and
>> There are a number of documents that have cat2_facet= "*Top Wear*". The
>> problem is the space between *Top and Wear*.
>>
>> results = Item.find_by_solr("[* TO *]",
>> {:facets=>{:zeros=>false,:fields=>[:cat1, :cat2] }})
>> results.facets["facet_fields"]
>>
>> return {"cat1_facet"=>{"electronics"=>5, "clothing"=>5},
>> *"cat2_facet"=>{"Bottom
>> Wear"=>1, "Top Wear"=>2*, "Shoes"=>2, "HDTV"=>1, "Camera"=>4}}
>>
>> When I issue the query below
>>
>> results = Item.find_by_solr("[* TO *] AND cat2:Shoes",
>> {:facets=>{:zeros=>false,:fields=>[:cat1, :cat2] }})
>>
>> It returned correct number of hits.  However when i run the query
>>
>> results = Item.find_by_solr("[* TO *] AND cat2:*Top Wear*",
>> {:facets=>{:zeros=>false,:fields=>[:cat1, :cat2] }})
>>
>> It return zero hit (incorrect).
>>
>> I even tried to put quote and double quote for the facet value
>>
>> @results = Item.find_by_solr("[* TO *] AND cat2:'*Top Wear'*",
>> {:facets=>{:zeros=>false,:fields=>[:cat1, :cat2] }})
>>
>> And it still does not work. What should I do to remedy this space issue?
>>
>> Let me also attach the  translated solr query I saw in solr log file
>>
>> INFO: [] webapp=/solr path=/select
>>
>> params={facet=true&fl=pk_i,score&facet.mincount=1&q=([*+TO+*]+AND+cat2_facet:Shoes)+AND+(type_s:Item)&facet.limit=-1&facet.field=cat1_facet&facet.field=cat2_facet&qt=standard&wt=ruby}
>> *hits=2* status=0 QTime=1
>>
>> Jun 5, 2009 7:54:23 PM org.apache.solr.core.SolrCore execute
>>
>> INFO: [] webapp=/solr path=/select
>>
>> params={facet=true&fl=pk_i,score&facet.mincount=1&q=([*+TO+*]+AND+cat2_facet:Top+Wear)+AND+(type_s:Item)&facet.limit=-1&facet.field=cat1_facet&facet.field=cat2_facet&qt=standard&wt=ruby}
>> *hits=0* status=0 QTime=10
>>
>> Thank you.
>> Thanh
>>
>
>

Re: Facet query return zero hits if category facet value has 2 or more words (looks like space does not work)

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jun 6, 2009, at 9:52 PM, Thanh Doan wrote:
> webapp=/solr path=/select
> params={facet=true&fl=pk_i,score&facet.mincount=1&q=([*+TO+*]+AND+*
> cat2_facet:Top+Wear*)+AND+ 
> (type_s:Item 
> )&facet 
> .limit 
> =-1&facet.field=cat1_facet&facet.field=cat2_facet&qt=standard&wt=ruby}
> *hits=0* status=0 QTime=10

...
>
>
> Have you ever used a string facet field in which the facet value  
> contains 2
> or more words like
> Brand:Hewlett Packard
>
> If yes, what the query looks like exactly to filter the results  
> based on the
> facet value = 'Hewlett Packard'?

If you have spaces in a string type field and need to query on it, you  
must surround it by quotes:   cat2_facet:"Top Wear"

You also need to be sure to escape any characters that can cause  
trouble with the query parser.

One tip from the query you have, separate out the facet drill in  
clause to an fq parameter: &fq=cat2_facet:"Top Wear" - it'll allow  
Solr to cache those separately.

	Erik