Java 在solr中从逗号分隔的字段中搜索字符串

Java 在solr中从逗号分隔的字段中搜索字符串,java,spring-mvc,solr,solrj,solr6,Java,Spring Mvc,Solr,Solrj,Solr6,我已在我的Spring MVC Java Web应用程序中安装了solr-6.5.1,参考了以下文档: 我有一个POJO声明,如下所示: public class WebContentSearchHB { private int webContentDefinitionId; private String pageTitle; private String pageKwd; private String pageDesc; private i

我已在我的
Spring MVC Java Web应用程序中安装了
solr-6.5.1
,参考了以下文档:

我有一个
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;
    }

}
[
{"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}
]
我没有创建任何
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();
http://localhost::8983/solr/swcm_qa/select?indent=on&q=category:7*&wt=json
我还向我的
pom.xml
文件添加了以下maven依赖项

<dependency>
    <groupId>org.apache.solr</groupId>
    <artifactId>solr-solrj</artifactId>
    <version>6.5.1</version>
</dependency>
这里有多个类别作为逗号分隔的值添加。现在,当我尝试搜索分类字段中的数据时,如下所示:

solrClient = new HttpSolrClient.Builder(solrUrl).build();
solrClient.setParser(new XMLResponseParser());
WebContentSearchHB searcHB = new WebContentSearchHB();
//codes to set data 
solrClient.addBean(searcHB);
solrClient.commit();
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
注释中以逗号分隔的字符串形式存储多个值?

在类别字段中,“2,6,7,8”被索引为单个字符串

category:["2,6,7,8"]
应该是

category:["2","6","7","8"]
在编制索引之前,您应该对该
类别
字段应用过滤器,以便将单个数值存储到字段中,并使用
作为分隔符

修改查询,如
q=category:*7*