35

I search for a word and I get the results with facet as follows:

<lst name="itemtype">
<int name="Internal">108</int>
<int name="Users">73</int>
<int name="Factory">18</int>
<int name="Supply Chain Intermediaries">6</int>
<int name="Company">1</int>
<int name="Monitor/Auditor firm">0</int>
</lst>

Then I wrote the condition like fq=itemtype:Factory. I get the results. But I am not getting the results for fq=itemtype:Supply Chain Intermediaries.
I am thinking the problem rests with the spaces in the condition (Supply Chain Intermediaries). I tried with urlencode (to replace spaces with %20) also. But it's of no use. Can you guys please help me to solve this?

Update:

For single value it is working fine. I build the query like this:

http:localhost:8080/solr/select/?q=adidas&version=2.2&indent=on&facet=on&start=0&rows=20&fq={!raw f=itemtype}Supply Chain Intermediaries

But i need to write for multiple values. The original Query with out raw is as follows

http://localhost/solr/select/?q=adidas&version=2.2&indent=on&facet=on&start=0&rows=20&fq=(itemtype:Company itemtype:Supply Chain Intermediaries)

Can you guys please help me to solve this.

Community
  • 1
  • 1
Brahmaji Rao
  • 395
  • 1
  • 4
  • 6

5 Answers5

45

How is your itemtype field analysed?

If it is of type string , then use:

fq=itemtype:"Supply Chain Intermediaries"

Otherwise you can also try:

fq=itemtype:(Supply Chain Intermediaries)

Assuming OR is the default operator in your config and text is the default search field, your query will get translated to:

fq=itemtype:Supply OR text:(Chain Intermediaries)

Chain and Intermediaries are searched against default search field.

rae1
  • 6,066
  • 4
  • 27
  • 48
Umar
  • 2,819
  • 20
  • 17
  • 3
    This helped. thank you. But what when we have some field name with white spaces? Pls advise. – Dharmik Bhandari Jul 23 '12 at 07:46
  • +1 Thanks, I'm using http://lbdremy.github.io/solr-node-client/ by the way and there is no conversion for array input types so it must be manually done. – King Friday May 08 '14 at 18:20
  • I'm building query using Solr Criteria(fieldname).contains(value) not working for me. Any suggestions? – Vignesh Sep 18 '17 at 14:39
21

I have tried different solutions mentioned here, but none of them worked. However I solved it like this:

fq=itemtype: *Supply\ Chain\ Intermediaries*

Here space will be escaped with \

The above string will match with the strings Lorem Supply Chain Intermediaries Ipsum

If you are having a word starts with Supply Chain Intermediaries Ipsum then just give

fq=itemtype: Supply\ Chain\ Intermediaries*
Sri Harsha
  • 310
  • 2
  • 7
2

This doesn't answer this question directly but it may help with this problem:

Remove the spaces before posting to Solr.

For fields used for faceting rather than searching, it is not important to store the value with spaces. The value is simply a treated as key. Store the field itemtype like so:"supplychainintermediaries", "monitorauditorfirm", etc.

When you display the facet values to the user, simply use a dictionary which maps key values to display values. Like so:

"supplychainintermediaries" --> "Supply Chain Intermediaries" "monitorauditorfirm" --> "Monitor/Auditor Firm"

James Lawruk
  • 30,112
  • 19
  • 130
  • 137
1

I guess you can use

fq={!raw f=itemtype}Supply Chain Intermediaries

for that purpose

It tuns out that you have to use !term instead of !raw for Solr version >= 4.0

http://mail-archives.apache.org/mod_mbox/lucene-solr-user/201012.mbox/%3C4D121F73.3090706@jhu.edu%3E

Have a nice day.

slhsen
  • 606
  • 9
  • 21
  • I wrote my new solr query. Can you please check and give suggestion. – Brahmaji Rao Apr 27 '11 at 05:30
  • 1
    @Brahmaji Do you need OR operation between filters or AND operation? For AND you can simply write multiple `fq` filters. But I guess you don't have much luck with OR. May be you can try to write your values between double quotes instead, such as `fq=text:"Chain Intermediaries"`. I haven't tried that one though. – slhsen Apr 27 '11 at 14:36
0

I have fixed white space issue by replacing :

$tmp[] = $name . ':' . $this->_escapeValue($value);

with :

$tmp[] = $name . ':' .'"'. $this->_escapeValue($value).'"';

Means by adding quotation after escape value in SolrSource.php file.

L Y E S - C H I O U K H
  • 4,765
  • 8
  • 40
  • 57