从solrResponse对象获取bean时发生问题。
虽然结果从数据库返回并且也会响应。何时,我尝试运行resp.getBeans(UserObj.class);
它返回零结果
当我从solr admin提示符运行查询时,它返回了适当的结果。因此,管理员方面已正确配置,因为我无法从结果中提取POJO对象。
请浏览UserObj.java和Controller代码。 还粘贴了schema.xml和db-data-config.xml代码。
- schema.xml中
<fields>
<field name="userId" type="sint" indexed="true" stored="true" required="true" omitNorms="true" />
<field name="firstName" type="string" indexed="true" stored="true" required="true" omitNorms="true" />
<field name="lastName" type="string" indexed="true" stored="true" omitNorms="true" />
<field name="login" type="string" indexed="true" stored="true" omitNorms="true" />
<field name="email" type="string" indexed="true" stored="true" omitNorms="true" />
<field name="status" type="string" indexed="true" stored="true" omitNorms="true" />
<field name="sig_address" type="string" indexed="true" stored="true" omitNorms="true" />
<!--<dynamicField name="roles_*" type="string" indexed="true" stored="true" omitNorms="true" />-->
<field name="roles_ids" type="sint" indexed="true" stored="true" multiValued="true" omitNorms="true" />
</fields>
<uniqueKey>userId</uniqueKey>
<defaultSearchField>userId</defaultSearchField>
- DB-数据-config.xml中
<dataConfig>
<dataSource driver="com.mysql.jdbc.Driver" url="dburl" user="user" password="password" />
<document name="users">
<entity name="user" pk ="userId" query="select userId, firstName, lastName, login,email,status,sig_address from USER"
deltaImportQuery="select userId, firstName, lastName, login, sig_address,email,status from USER where userId='${dataimporter.delta.userId}'"
deltaQuery="select userId from USER where timeStamp >= '${dataimporter.last_index_time}'" >
<field column="userId," name="userId" />
<field column="firstName" name="firstName" />
<field column="lastName" name="lastName" />
<field column="login" name="login" />
<field column="email" name="email" />
<field column="status" name="status" />
<field column="sig_address" name="sig_address" />
<!--
<entity name="user_roles" pk="refid" transformer="script:addRoles" query="select usd.refid, usd.refvalue , usr_bak.name from USER_SETDATAS usd, USER_ROLES_BAK usr_bak where usd.refvalue = usr_bak.id
and usd.refid=${user.userId} and usd.fieldname='ROLES'"
deltaQuery="select refid from USER_SETDATAS where last_modified >= '${dataimporter.last_index_time}'"
deletedPkQuery="select refid from USER_SETDATS_BAK_LOG where timeStamp >= '${dataimporter.last_index_time}'"
parentDeltaQuery="select userId from USER where userid=${user_roles.refid}" >
<field column="refvalue" name="roles_ids" />
</entity>
-->
</entity>
</document>
- 控制器代码
userSolrBean.setParser(new XMLResponseParser());
SolrQuery query = new SolrQuery();
String userQuery = "";
if(email!=null)
userQuery="email :*"+email+"*";
if(login!=null)
userQuery="login :*"+login+"*";
if(email!=null && login!=null)
userQuery="email :*"+email+"* OR login:*"+login+"*";
log.info("solr query for user search is :"+userQuery);
query.set("q",userQuery);
query.setRows(0);
query.setFacetLimit(-1);
query.setFacetMinCount(1);
QueryResponse resp= userSolrBean.query(query, METHOD.POST);
filteredUsers=resp.getBeans(UserObj.class);
- UserObj.java
@XmlRootElement(name = "UserObj")
公共类UserObj {
@Field("doc_id")
private String doc_id;
@Field("doc_type")
private String doc_type;
@Field("userId")
private String userId;
@Field("firstName")
private String firstName;
@Field("lastName")
private String lastName;
@Field("login")
private String login;
@Field("email")
private String email;
@Field("status")
private String status;
@Field("sig_address")
private String sig_address;
/*
@Field("roles_ids")
private List<String> roles_ids = new ArrayList();
public String getDoc_id() {
return doc_id;
}*/
public void setDoc_id(String doc_id) {
this.doc_id = doc_id;
}
public String getDoc_type() {
return doc_type;
}
public void setDoc_type(String doc_type) {
this.doc_type = doc_type;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getSig_address() {
return sig_address;
}
public void setSig_address(String sig_address) {
this.sig_address = sig_address;
}
/*
public List<String> getRoles_ids() {
return roles_ids;
}
public void setRoles_ids(List<String> roles_ids) {
this.roles_ids = roles_ids;
}
*/
}
答案 0 :(得分:1)
您必须使用适当的值来返回要返回的对象数。零将执行查询并计算符合给定条件的文档。
query.setRows(10); //return 10 documents
query.setStart(0); //starting at the first