-->
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.  [ 4 posts ] 
Author Message
 Post subject: hibernate search gives no results.
PostPosted: Wed Jul 02, 2008 11:09 am 
Regular
Regular

Joined: Tue Apr 01, 2008 5:39 pm
Posts: 61
Thanks everyone for the previous help.

3.2.6 GA

Mapping documents:
Code:

@Indexed(index="AuditTrail")
public class AuditTrail implements Serializable {
    private static final long serialVersionUID = 54324L;

    @DocumentId
    private Integer id;

    @Field(index=Index.TOKENIZED, store=Store.YES)
    @Analyzer(impl=KeywordAnalyzer.class)
    @Boost(value=2)
    private String function;

    @Field(index=Index.TOKENIZED, store=Store.YES)
    @Analyzer(impl=KeywordAnalyzer.class)
    @Boost(value=2)
    private String attribute;

    @Field(index=Index.TOKENIZED, store=Store.YES)
    @Analyzer(impl=KeywordAnalyzer.class)
    @Boost(value=2)
    private String oldValue;

    @Field(index=Index.TOKENIZED, store=Store.YES)
    @Analyzer(impl=KeywordAnalyzer.class)
    @Boost(value=2)
    private String newValue;
   
     // getters and setters
}



Code between sessionFactory.openSession() and session.close():
Code:
@Override
    public List<AuditTrail> getBySearch(final String searchTerm, final String[] fields,
           final int startPos, final int maxSize) {
        return forceGenericList(getHibernateTemplate().executeWithNativeSession(
                new HibernateCallback()
                {
                    public Object doInHibernate(Session session) throws HibernateException
                    {
                        try
                        {
                            FullTextSession fullTextSession = Search.createFullTextSession(session);
                            QueryParser parser = new MultiFieldQueryParser(fields, new SnowballAnalyzer("English"));
                            Query query = parser.parse(searchTerm);
                            org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery(query,AuditTrail.class);
                            fullTextQuery.setFirstResult(startPos);
                            fullTextQuery.setMaxResults(maxSize);
                            return fullTextQuery.list();
                        }
                        catch (ParseException pe)
                        {
                             return new LinkedList<AuditTrail>();
                        }
                    }
                }));
    }


my test case.
Code:
@Test
    public void testSearchAuditedTrail()
    {
        final int sizeBefore1 = this.auditTrailService.searchAuditedTrail("some stuff", new String[]{"oldValue", "newValue", "note"}).size();
        final int sizeBefore2 = this.auditTrailService.searchAuditedTrail("admin", new String[]{"createBy.username", "function"}).size();
        this.auditTrailService.log(this.auditTrail, this.auditTrail2, this.user, "some stuff");
        Assert.assertEquals(this.auditTrailService.searchAuditedTrail("some stuff", new String[]{"date"}).size(), 0);
        Assert.assertEquals(this.auditTrailService.searchAuditedTrail("some stuff", new String[]{"oldValue", "newValue", "note"}).size(), (sizeBefore1+1));
        Assert.assertEquals(this.auditTrailService.searchAuditedTrail(this.user.getUsername(), new String[]{"createBy.username", "function"}).size(),(sizeBefore2+1));
    }




the service is just wrapper around the dao. I check the results and it happens to be 0. What is wrong? I check the index and they are created.


Last edited by cablepuff on Mon Aug 18, 2008 9:41 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 02, 2008 7:30 pm 
Regular
Regular

Joined: Tue Apr 01, 2008 5:39 pm
Posts: 61
do i need to commit before i can get the search result? is their anyway to do this without doing tx.commit();


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 2:22 am 
Regular
Regular

Joined: Tue Apr 01, 2008 5:39 pm
Posts: 61
sorry for the bump.

It would be great if someone can tell me what i did wrong.

I also try doing

Transaction tx = fullTextSession.beginTransaction();

....

tx.commit();


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 09, 2008 4:59 pm 
Regular
Regular

Joined: Tue Apr 01, 2008 5:39 pm
Posts: 61
the error is that i was different analzyer.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.