休止状態の検索でいくつかの実験を行っています。これまでのところ、インデックスと構成を作成できました。インデックスが作成され、ルークを使用して既に検証済みです。しかし、検索しようとすると、結果が返されません。ファセットリクエストは非常にうまく機能します。
実在物
@Entity
@Table(name = "user_profile")
@Root(name = "candidate")
@XmlRootElement
@Indexed
@Analyzer(impl = StandardAnalyzer.class)
public class ProfileBean implements Serializable, DataModel {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@Element
@DocumentId
private Integer id;
@NotNull
@Length(max = 25)
@Element(required=false)
@Column(name = "first_name")
@Field(index = Index.YES,analyze = Analyze.YES, store = Store.YES)
private String firstName;
@Column(name = "last_name")
@NotNull
@Length(max = 25)
@Element(required=false)
@Field(index = Index.YES,analyze = Analyze.YES, store = Store.YES)
private String lastName;
@Column(name = "email")
@Length(max = 25)
@Element
@Field(index = Index.YES,analyze = Analyze.YES, store = Store.YES)
private String email;
@Column(name = "city")
@NotNull
@Length(max = 30)
@Element(required=false)
@Field(index = Index.YES,analyze = Analyze.NO, store = Store.YES)
private String city;
@Column(name = "country")
@NotNull
@Length(max = 25)
@Element(required=false)
@Field(index = Index.YES,analyze = Analyze.NO, store = Store.YES)
private String country;
@Column(name = "occupation")
@Length(max = 25)
@Element(required=false)
@Field(index = Index.YES,analyze = Analyze.NO, store = Store.YES)
private String occupation;
}
索引付けコード
FullTextSession fts =
org.hibernate.search.Search.getFullTextSession(getSession());
List<ProfileBean> profiles = super.listAll();
for (ProfileBean item : profiles) {
fts.index(item); //manually index an item instance
}
ファセット検索コード (非常にうまく機能します)
FullTextSession fts =
org.hibernate.search.Search.getFullTextSession(getSession());
QueryBuilder builder = fts.getSearchFactory()
.buildQueryBuilder().forEntity(ProfileBean.class).get();
FacetingRequest cityFacetingRequest = builder.facet()
.name("cityFaceting").onField("city").discrete()
.orderedBy(FacetSortOrder.COUNT_DESC).includeZeroCounts(false)
.createFacetingRequest();
Query luceneQuery = builder.all().createQuery();
FullTextQuery fullTextQuery = fts.createFullTextQuery(luceneQuery, ProfileBean.class);
FacetManager facetManager = fullTextQuery.getFacetManager();
facetManager.enableFaceting(cityFacetingRequest);
List<Facet> facets = facetManager.getFacets("cityFaceting");
for (Facet f : facets) {
System.out.println(f.getValue() + " (" + f.getCount() + ")");
List<ProfileBean> profiles = fts.createFullTextQuery(
f.getFacetQuery(),ProfileBean.class).list();
for (final ProfileBean p : profiles) {
System.out.println(p.getFirstName() + " (" + p.getLastName()
+ ")");
}
}
動作していないコードの検索
FullTextSession fts =
org.hibernate.search.Search.getFullTextSession(getSession());
QueryBuilder builder = fts.getSearchFactory()
.buildQueryBuilder().forEntity(ProfileBean.class).get();
Query query = builder.keyword().
onFields("occupation", "city", "country").
matching("engineer").createQuery();
FullTextQuery fullTextQuery = fts.createFullTextQuery(query, ProfileBean.class);
List<ProfileBean> profiles = fullTextQuery.list();
for(ProfileBean bean: profiles){
System.out.println("First Name: "+bean.getFirstName()+" ,Last Name:"+bean.getLastName()+" ,Occupation:"+bean.getOccupation());
}
私はすべてのタイプの Lucene クエリを試しましたが、何も役に立ちません。