我在Spring MVC Java Web Application
闖民宅以下單證安裝solr-6.5.1
: http://www.baeldung.com/apache-solrj搜索從一個逗號字符串分隔場Solr中
https://github.com/eugenp/tutorials/tree/master/apache-solrj/src/main/java/com/baeldung/solrjava
我有一個POJO
聲明如下:
我還沒有創建任何schema.xml
文件或編輯現有的schema.xml
文件。我手動在POJO
中的值,每個字段,並使用我的應用程序如下其添加到Solr的索引:
solrClient = new HttpSolrClient.Builder(solrUrl).build();
solrClient.setParser(new XMLResponseParser());
WebContentSearchHB searcHB = new WebContentSearchHB();
//codes to set data
solrClient.addBean(searcHB);
solrClient.commit();
我還增加了以下Maven依賴我pom.xml
文件
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>6.5.1</version>
</dependency>
WebContentSearchHB class
中的一個字段名爲category
將包含該內容的各種類別的逗號分隔的字符串。 的採樣數據看起來像如下所示的一個:
[
{"pageTitle":["Test page"],
"pageKwd":["Test page"],
"pageDesc":["Test page"],
"applicationId":[1],
"siteId":[5],
"category":["2,6,7,8"],
"pageCreatedTime":["2017-02-17T05:58:19.648Z"],
"pageUpdatedDate":["2017-06-12T03:46:45.489Z"],
"webContentDefinitionId":[4947],
"webContentType":["simplewebcontent.html"],
"id":"717821d9-989e-4c4f-b66a-8b5185ed88ca",
"webContentData":"test"],
"_version_":1570012287149801472}
]
這裏有多個類別添加作爲逗號分隔值。現在,當我嘗試在類別字段中搜索數據時,如下所示:
http://localhost::8983/solr/swcm_qa/select?indent=on&q=category:7*&wt=json
不返回任何數據。但是,如果我搜索如下,
http://localhost::8983/solr/swcm_qa/select?indent=on&q=category:2*&wt=json
其中2
顯示爲逗號分隔字符串的第一個值的所有行返回。如何從類別字段中的逗號分隔值中搜索字符串?另外,如何在@Field
註釋中指定字段是否將多個值存儲爲以逗號分隔的字符串?