-->
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.  [ 2 posts ] 
Author Message
 Post subject: index updated but no result on search
PostPosted: Thu May 02, 2013 4:17 am 
Newbie

Joined: Mon Feb 28, 2011 10:12 am
Posts: 1
Hello,

Im using spring 4.1.2.Final,
Hibernate-search 4.2.0.Final

I have a strange behavior in my code.
I send an update request to change the string value of a field in a class.
With Luke I can see that the index has been updated with the new value I have set on the field.
Searching for the new field value in Luke will return a successful result, this is correct.
Searching for the old value in Luke will not return any value, this is correct.

Sending a request in my implemented code to retrive the value will only work with the old value...?
It seems like the old value is cached somewhere..

After restarting the application I do get a search result for the new value.
The index is rebuild when staring the application.

My entity class
Code:
@Entity
@DynamicUpdate(value = true)
@Indexed
public class DAvtal extends DomanObjekt {
@DocumentId
    @Id
    @Column(name = "AVTAL_ID")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "AVTAL_SEQ_GEN")
    @GenericGenerator(name = "AVTAL_SEQ_GEN", strategy = "sequence", parameters = {@Parameter(name = "sequence", value = "SEQ_AVTAL")})
    private Long avtalId;

@Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
    @Analyzer(definition = "customanalyzer")
    @Column(name = "ALTERNATIVT_NAMN")
    private String alternativtNamn;
}


This is specified in the superclass
Code:
@AnalyzerDef(name = "customanalyzer",
        tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
        filters = {@TokenFilterDef(factory = LowerCaseFilterFactory.class),
                @TokenFilterDef(factory = SnowballPorterFilterFactory.class, params = {@Parameter(name = "language", value = "Swedish")})
        })


The query should not really be relevant since it works but it looks like this.
Code:
public List<DUtforandeVerksamhet> sokUtforandeverksamhetFritext(String fritext, int sidnummer, int sidstorlek) {
        FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(this.getEntityManager());
        QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(DUtforandeVerksamhet.class).get();
        Date today = new Date();

        BooleanJunction booleanJunction = queryBuilder
                .bool()
                .must(queryBuilder
                        .range()
                        .onField("avtal.avtalsperiodsStart")
                        .below(today).createQuery())
                .must(queryBuilder
                        .range()
                        .onField("avtal.avtalsperiodsSlut")
                        .above(today).createQuery())
                .must(queryBuilder
                        .keyword()
                        .fuzzy()
                        .withThreshold(.5f)
                        .withPrefixLength(0)
                        .onFields("namn",
                                "avtal.alternativtNamn")
                        .matching(fritext).createQuery());

        org.hibernate.search.jpa.FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery(booleanJunction.createQuery(), DUtforandeVerksamhet.class);
        fullTextQuery.setSort(new Sort(new SortField("namn", SortField.STRING)));
        fullTextQuery.setFirstResult((sidnummer - 1) * sidstorlek);
        fullTextQuery.setMaxResults(sidstorlek);
        return fullTextQuery.getResultList();
    }


/Micke

EDIT!!
Just discovered that I need to set the @ContainedIn on the child-side of the association. Problem solved !!


Top
 Profile  
 
 Post subject: Re: index updated but no result on search
PostPosted: Tue May 07, 2013 11:17 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
nice, well spotted!
(and welcome)

_________________
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.  [ 2 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.