2017-01-28 16 views
0

我想在我的測試開始時運行一個solr查詢以獲得一堆列表,然後我將使用在測試運行中。Solr查詢在瀏覽器中工作,但不使用RestTemplate org.apache.solr.search.SyntaxError:無法解析

如果我提出這個要求在Chrome中我得到的JSON響應:

MYAPIDOMAIN/solr/listings/select?q=category:commercial+AND+property_type:office&fl=listing_id,listing_status&group=true&group.main=true&group.field=listing_status&group.limit=1&rows=100&wt=json&indent=on

在我使用了Spring RestTemplate撥打電話,然後我解析JSON響應的測試,它爲我的一些查詢,但對於這個我剛剛得到一個錯誤回來:

"responseHeader":{ 
    "status":400, 
    "QTime":7, 
    "params":{ 
     "q":"category:commercial%2BAND%2Bproperty_type:office", 
     "group.main":"true", 
     "indent":"on", 
     "fl":"listing_id,listing_status", 
     "group.limit":"1", 
     "rows":"100", 
     "wt":"json", 
     "group.field":"listing_status", 
     "group":"true"}}, 
    "error":{ 
    "msg":"org.apache.solr.search.SyntaxError: Cannot parse 'category:commercial%2BAND%2Bproperty_type:office': Encountered \" \":\" \": \"\" at line 1, column 41.\nWas expecting one of:\n <EOF> \n <AND> ...\n <OR> ...\n <NOT> ...\n \"+\" ...\n \"-\" ...\n <BAREOPER> ...\n \"(\" ...\n \"*\" ...\n \"^\" ...\n <QUOTED> ...\n <TERM> ...\n <FUZZY_SLOP> ...\n <PREFIXTERM> ...\n <WILDTERM> ...\n <REGEXPTERM> ...\n \"[\" ...\n \"{\" ...\n <LPARAMS> ...\n <NUMBER> ...\n ", 
    "code":400}} 

我不知道,我只是給了他們在測試中使用的Solr查詢什麼,很明顯這是一個編碼的問題,但我不知道哪裏。我試過使用URLEncoder,我發現了一些在線URL編碼器,但似乎沒有任何工作。

有人可以告訴我這有什麼問題嗎?我還有5個需要做的查詢,所以我確實需要修復。

謝謝

回答

0

我嘗試同樣對我的地方,發現了同樣的錯誤,這是由於編碼值%2B - > +在你的語法。它打破瞭解析器。

因此,您可以使用空格而不是+,它將更改爲%20。那麼它應該工作正常。

+0

謝謝你完美的作品! – MisterMan

+0

@MisterMan太棒了 –

相關問題