用compass做一个站内搜索,我有一个地区表,是多级的,如下: package net.shopxx.entity;import java.util.Set;import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import org.apache.commons.lang.StringUtils;
import org.compass.annotations.Lazy;
import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableComponent;
import org.compass.annotations.SearchableParent;
import org.compass.annotations.SearchableProperty;
import org.compass.annotations.SearchableReference;/**
* 实体类 - 地区
*/
@Searchable
@Entity
@javax.persistence.Table(name="area", uniqueConstraints = {@UniqueConstraint(columnNames = {"name", "parent_id"})})
public class Area extends BaseEntity {private static final long serialVersionUID = -2158109459123036967L;public static final String SEPARATOR = ",";// 树路径分隔符private String name;// 地区名称
private String path;// 树路径
private Boolean isLeaf = true;// 是否是叶节点
private Area parent;// 上级地区
private Set children;// 子地区
private Set storeSet; // 餐馆地段
private Integer clickNum = 0;// 点击量
private Set metroSectionSet; // 地铁与区县集合
private Set metroAreaSet; // 地铁与地段集合@OneToMany(mappedBy = "area", fetch = FetchType.LAZY)
public Set getStoreSet() {
return storeSet;
}public void setStoreSet(Set storeSet) {
this.storeSet = storeSet;
}@SearchableProperty(store=org.compass.annotations.Store.YES)
@Column(nullable = false)
public String getName() {
return name;
}public void setName(String name) {
this.name = name;
}@Column(length = 1000)
public String getPath() {
return path;
}@Column(nullable = false)
public Boolean getIsLeaf() {
return isLeaf;
}public void setIsLeaf(Boolean isLeaf) {
this.isLeaf = isLeaf;
}public void setPath(String path) {
this.path = path;
}@SearchableComponent
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id")
public Area getParent() {
return parent;
}public void setParent(Area parent) {
this.parent = parent;
}@SearchableComponent
@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)public Set getChildren() {
return children;
}public void setChildren(Set children) {
this.children = children;
}
public Integer getClickNum() {
return clickNum;
}public void setClickNum(Integer clickNum) {
this.clickNum = clickNum;
}// 获取地区的层级(顶级分类:0)
@Transient
public Integer getLevel() {
if (StringUtils.isEmpty(path)) {
return 0;
} else {
return path.split(SEPARATOR).length;
}
}@ManyToMany(fetch = FetchType.LAZY, mappedBy = "sectionSet")
@JoinTable(name = "metrosection")
public Set getMetroSectionSet() {
return metroSectionSet;
}public void setMetroSectionSet(Set metroSectionSet) {
this.metroSectionSet = metroSectionSet;
}@ManyToMany(fetch = FetchType.LAZY, mappedBy = "areaSet")
@JoinTable(name = "metroarea")
public Set getMetroAreaSet() {
return metroAreaSet;
}public void setMetroAreaSet(Set metroAreaSet) {
this.metroAreaSet = metroAreaSet;
}}里面包含省、市、区、县、镇、村、街道等七个级别的区域,我用compass搜索的时候他只搜索一个级别。如:第一条:四川--成都市--金牛区;第二条:四川--成都市--金牛区--青羊小区。。我输入“金牛”,按理说两条都应该出来,因为第二条进而也有金牛区,只不过它在第二级,但它只搜索了第一条,不搜索第二条,第二级它不去搜索。如果我输入“青羊”,它就找不到第一条,也就是说,它不去搜索有@SearchableComponent的parent,这个问题怎么解决呢?请各位指点指点,谢谢!。本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/izgnaw/archive/2010/09/07/5868766.aspx