質問

Problem happening while fetching the beans from solrResponse object. Though results are getting returned from database and coming in response also. When,I try to run resp.getBeans(UserObj.class); It returns zero result When I'm running the query from solr admin prompt it's returning appropriate results.So, admin side is properly configured by I'm not able to extract the POJO object from result.

Please go through UserObj.java and Controller code. Also pasted schema.xml and db-data-config.xml code.

--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-data-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>

--Controller Code

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")

public class 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;
}
*/

}

役に立ちましたか?

解決

You have to use a proper value for the number of objects to be returned. Zero will just execute the query and count documents matching given criteria.

query.setRows(10);  //return 10 documents
query.setStart(0); //starting at the first 
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top