Thanks for the reply,
hardy.ferentschik wrote:
Assuming that you have an @Indexed on on Cat and you don't want index CatPriority and CatType at all -
--Hardy
I want the id of catType in Cat Index.
hardy.ferentschik wrote:
Not sure what the relation is between Cat and Label (if there is any).
Hope this helps,
--Hardy
No relation between Cat And Label
names of all other entities like CatType, CatPriority are decoupled from their tables and placed in Label so that language specific names can be added with out touching the main tables. this is the schema.
CREATE TABLE `t_cat` (
`cat_id` bigint(20) NOT NULL auto_increment,
`description` varchar(255) collate utf8_unicode_ci default NULL,
`cat_type_id` bigint(20) NOT NULL,
`cat_priority_id` bigint(20) NOT NULL,
`create_date` datetime NOT NULL,
PRIMARY KEY (`cat_id`),
KEY `i_cat_type_id` (`cat_type_id`),
KEY `i_cat_priority_id` (`cat_priority_id`)) ENGINE=InnoDB ..
CREATE TABLE `t_cat_type` (
`cat_type_id` bigint(20) NOT NULL auto_increment,
`create_date` datetime NOT NULL,
PRIMARY KEY (`cat_type_id`)) ENGINE=InnoDB
CREATE TABLE `t_cat_priority` (
`cat_priority_id` bigint(20) NOT NULL auto_increment,
`create_date` datetime NOT NULL,
PRIMARY KEY (`cat_priority_id`)) ENGINE=InnoDB
CREATE TABLE `t_label` (
`label_id` bigint(20) NOT NULL auto_increment,
`name` varchar(255) collate utf8_unicode_ci default NULL,
`code` varchar(255) collate utf8_unicode_ci default NULL,
`language_id` bigint(20) NOT NULL,
`cat_type_id` bigint(20) NOT NULL,
`cat_priority_id` bigint(20) NOT NULL,
`create_date` datetime NOT NULL,
PRIMARY KEY (`label_id`),
KEY `i_cat_type_id` (`cat_type_id`),
KEY `i_cat_priority_id` (`cat_priority_id`)) ENGINE=InnoDB ....
So, this t_label table is like a matrix. The row indicating name for a cat type will have its cat_type_id , name ,language id set to the corresponding values, and cat_priority_id is set to null or zero. similarly, The row representing cat priority name , we set the cat_priority_id and cat_type_id is null.
So my problem is my result set needs the names of properties like catType,CatPriority of Cat.
I have tow approaches at my hand ,
I. having two indexs
1. Cat index 2. Label Index
I execute search query on Cat Index, based on cat id, cat description , cat type Id, cat Prority Id and projecting on same fields. For each result I am executing two queries on Label index to get cat type name and cat priority name. The problem is i am not able to sort the search result based on names of cat type and priority.
II . Having single index using my modified CatType ,CatPriority and Label domains. ( I have indexedEmbedded lableSet for Cat type and priority)
@Indexed
class CatType{
Long catTypeId;
@IndexedEmbedded
@OnetoMany( mappedBy="catTypeId")
Set<Label> labelSet;
}
@Indexed
class Label{
@DocumentID
private Long labelId;
@Fields( {
@Field(name="name_sort",index=Index.UN_TOKENIZED),
@Field(name="name_token",index=Index.TOKENIZED)})
private String name;
@Field(index=Index.UN_TOKENIZED))
private Long langId;
@Field(index=Index.UN_TOKENIZED)
private Long catPriorityId;
@Field(index=Index.UN_TOKENIZED))
private Long catTypeId;
}
But when I use projection like 'cat.catType.labelSet.name' i am getting null for it , though indexed values present for it.
So , I am looking for any optimal approach in this situation. I am actually trying to get entire thing from index.