我已经安装solr-6.5.1
在我Spring MVC Java Web Application
的参考以下文档中:
http ://www.baeldung.com/apache-solrj
https://github.com/eugenp/tutorials/tree/master/apache-solrj/src/main/java/com/baeldung/solrjava
我有一个POJO
如下所示的声明:
public class WebContentSearchHB
{
private int webContentDefinitionId;
private String pageTitle;
private String pageKwd;
private String pageDesc;
private int siteId;
private int applicationId;
private Date pageCreatedTime;
private Date pageUpdatedDate ;
private String webContentData;
private String webContentType;
private String category;
public int getWebContentDefinitionId()
{
return webContentDefinitionId;
}
@Field("webContentDefinitionId")
public void setWebContentDefinitionId(int webContentDefinitionId)
{
this.webContentDefinitionId = webContentDefinitionId;
}
public String getPageTitle()
{
return pageTitle;
}
@Field("pageTitle")
public void setPageTitle(String pageTitle)
{
this.pageTitle = pageTitle;
}
public String getPageKwd()
{
return pageKwd;
}
@Field("pageKwd")
public void setPageKwd(String pageKwd)
{
this.pageKwd = pageKwd;
}
public String getPageDesc()
{
return pageDesc;
}
@Field("pageDesc")
public void setPageDesc(String pageDesc)
{
this.pageDesc = pageDesc;
}
public int getSiteId()
{
return siteId;
}
@Field("siteId")
public void setSiteId(int siteId)
{
this.siteId = siteId;
}
public int getApplicationId()
{
return applicationId;
}
@Field("applicationId")
public void setApplicationId(int applicationId)
{
this.applicationId = applicationId;
}
public Date getPageCreatedTime()
{
return pageCreatedTime;
}
@Field("pageCreatedTime")
public void setPageCreatedTime(Date pageCreatedTime)
{
this.pageCreatedTime = pageCreatedTime;
}
public Date getPageUpdatedDate()
{
return pageUpdatedDate;
}
@Field("pageUpdatedDate")
public void setPageUpdatedDate(Date pageUpdatedDate)
{
this.pageUpdatedDate = pageUpdatedDate;
}
public String getWebContentData()
{
return webContentData;
}
@Field("webContentData")
public void setWebContentData(String webContentData)
{
this.webContentData = webContentData;
}
public String getWebContentType()
{
return webContentType;
}
@Field("webContentType")
public void setWebContentType(String webContentType)
{
this.webContentType = webContentType;
}
public String getCategory() {
return category;
}
@Field("category")
public void setCategory(String category) {
this.category = category;
}
}
我没有创建任何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();
我还在我的pom.xml
文件中添加了以下 maven 依赖项
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>6.5.1</version>
</dependency>
WebContentSearchHB class
我在, named中的一个字段category
将包含该内容的各种类别的 id 的逗号分隔字符串。示例数据如下所示:
[
{"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
注释中的逗号分隔字符串?