-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: projection on classBridge created properties
PostPosted: Mon Aug 22, 2011 1:36 pm 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Hi,

I'm trying to retrieve a set of properties that are created inside a classbridge (language specific labels) and are therefore not annotated properties which can have the TwoWayFieldBridge which is described in the documentation as a requirement to be able to do a projection on the fields.

I've reviewed HSEARCH-372 but it seems to allow for only one name. I'm creating fields such as label_en, label_es etc and therefore need access to more than one field, although I search for only one field (language) at a time.

How do I get around this?

Kind regards,
Marc


Top
 Profile  
 
 Post subject: Re: projection on classBridge created properties
PostPosted: Tue Aug 23, 2011 6:19 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Perhaps some code will help to make my problem clearer

TagClassBridge
Code:
public void set(
      String name,
      Object value,
      Document document,
      LuceneOptions luceneOptions) {

   Tag tag = (Tag) value;
   
   Field field = new Field( "id",tag.getId().toString(),Store.YES,Index.NOT_ANALYZED);
   document.add(field);
      
   for(Locale locale : locales){
      //we need to create a tag version for each language.
      if(tag.getMessageKey() == null){      
         field = new Field("tag_" + locale.getLanguage(),tag.getLabel(),Store.YES,Index.ANALYZED);
      }else{
         field = new Field("tag_" + locale.getLanguage(),messages.getMessage(tag.getMessageKey(), null, locale),Store.YES,Index.ANALYZED);
      }
      document.add(field);
   }
}


Code:
FullTextSession fts = Search
      .getFullTextSession(getHibernateTemplate()
            .getSessionFactory().getCurrentSession());

BooleanQuery bq = new BooleanQuery();

QueryBuilder qb = fts.getSearchFactory().buildQueryBuilder()
      .forEntity(Tag.class).get();

Query q2 = qb
   .keyword()
   .wildcard()
   .onField("tag_" + language.getLanguageCode())
   .ignoreFieldBridge()
   .matching(query + "*")
   .createQuery();

bq.add(q2, Occur.MUST);

FullTextQuery qry = fts.createFullTextQuery(bq, Tag.class);
qry.setProjection("id", "tag_" + language.getLanguageCode());
qry.setSort(new Sort(new SortField("tag_"
      + language.getLanguageCode(), SortField.STRING)));
qry.setFirstResult(start);
qry.setMaxResults(max);
qry.setCacheable(true);
qry.setCacheRegion(CacheRegion.SELDOMCHANGE);

List<Object[] results = qry.list();



The results contain object arrays with the id for the Tag and null values for the selected field.


Top
 Profile  
 
 Post subject: Re: projection on classBridge created properties
PostPosted: Wed Aug 24, 2011 1:35 pm 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Help anyone?


Top
 Profile  
 
 Post subject: Re: projection on classBridge created properties
PostPosted: Wed Aug 24, 2011 1:45 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi Marc,
sorry for the delay; busy times.

Are you sure that
Code:
"tag_" + locale.getLanguage()

and
Code:
"tag_" + language.getLanguageCode()

produce the same String ?

Maybe check that first; if it still doesn't work please open an issue and a test I'll be glad to debug it.

Since you get null as results, it seems likely to me that you're projecting a non-existing field; or maybe a field which doesn't exist for the matching documents.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: projection on classBridge created properties
PostPosted: Tue Aug 30, 2011 11:11 am 
Newbie

Joined: Thu Jul 21, 2011 6:26 am
Posts: 8
hi guys,

I am seeing exactly the same problem on HS 3.4.1.

i add a field that is marked as Stored and Untokenized:-

Code:
   
        @ClassBridge(name = "adAttributes", index = Index.UN_TOKENIZED, store = Store.YES, impl = AdAttributesClassBridge.class)

        @Override
   public void set(String name, Object value, Document document, LuceneOptions opt)
        {
            field = new Field("testProjection", "is it working", opt.getStore(), opt.getIndex());
            document.add(field);
        }

        showQuery.setProjection("testProjection", "adAttributes.testProjection");


These returns empty when referenced. Any ideas?


Top
 Profile  
 
 Post subject: Re: projection on classBridge created properties
PostPosted: Tue Aug 30, 2011 6:56 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
These returns empty when referenced. Any ideas?

That really needs to be fixed. Please open an issue on JIRA:
https://hibernate.onjira.com/browse/HSEARCH

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: projection on classBridge created properties
PostPosted: Wed Aug 31, 2011 9:05 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
I've created the issue: https://hibernate.onjira.com/browse/HSEARCH-890

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.