ulrich (7) [Avatar] Offline
#1
Hello,

Is it plans to add implicitly the score to bean via an annotation for example? In my bean, if I have a property or method like :

@Score
private float score;

HS will inject the score result after the query in my bean.

Thank you,
Ulrich
john.griffin (36) [Avatar] Offline
#2
Re: Adding Lucene Score
Ulrich,

Not as far as I know. That doesn't mean it can't be added. Put in a JIRA issue on it at http://opensource.atlassian.com/projects/hibernate/secure/Dashboard.jspa. When Emmanuel gets back from vacation on or about the 21st I'll discuss it with him.

Thanks

John Griffin
ulrich (7) [Avatar] Offline
#3
Re: Adding Lucene Score
Thank you for response John, I will put a JIRA.

Have a nice day,
Ulrich

PS : Maybe i could to see him in Paris smilie
john.griffin (36) [Avatar] Offline
#4
Re: Adding Lucene Score
Not this time, he's in the Grand Canyon and Zion Nat. Park. :>O

John G.
emmanuel.bernard (101) [Avatar] Offline
#5
Re: Adding Lucene Score
I am open to such a feature but someone has to explain me the use case for it smilie
ulrich (7) [Avatar] Offline
#6
Re: Adding Lucene Score
In fact to get scores we must use projections? If I want to display and sort my bean list by score in my view, I must to inject score after result processing in my POJO or DTO to have values. So my "dream" would be to have implicity this values by an annotation propery to avoid double backend process.

Ulrich
emmanuel.bernard (101) [Avatar] Offline
#7
Re: Adding Lucene Score
Oh I see.
I thought you wanted to store a boost factor and use it dynamically for the entity.

For your usecase, I would use a ResultTransformer that can populate the score value where you want.
ulrich (7) [Avatar] Offline
#8
Re: Adding Lucene Score
Thank you,

It's an elegent solution.

Ulrich
dafe52 (3) [Avatar] Offline
#9
Re: Adding Lucene Score
Hello, I'm a beginner using Hibernate Search, and I want to add Lucene Score to my bean...

I try to use a ResultTransformer, but I need to set a Criteria to pre-filter my data, and If I project a property out of the index, the query return null...

I'm very glad if you put a simple example of how to add lucene score to a fullTextQuery without projecting FullTextQuery.SCORE...

Another issue is the following:

I try to perform a FullTextQuery using fullTextSession and setting a Criteria query... the problem appears when I put "setMaxResults"... All the time cuts the resultset to "count-1" elements...

Thank you for your attention. David
emmanuel.bernard (101) [Avatar] Offline
#10
Re: Adding Lucene Score
To your first problem, here is a possibility

List<Object[]> results = query.setProjection(FullTextQuery.THIS, FullTextQuery.SCORE).list();

results.get(0)[0].getClass() == Dvd.class
results.get(0)[1] == .93743 (score)

A result transformer can make all this look better but the key is to use THIS to retrieve the actual managed object when projecting
emmanuel.bernard (101) [Avatar] Offline
#11
Re: Adding Lucene Score
What is count? and how does your Criteria query look like?
dafe52 (3) [Avatar] Offline
#12
Re: Adding Lucene Score
Thank you very much

I solved the second problem... but about the first one...

If I use FullTextQuery.THIS or FullTextQuery.SCORE the results of my query are all matching the fullTextQuery, but not pre-filtered with the Criteria ... It is normal because SCORE must be get for all the results retrieved from the index, but I want to filter this results with a criteria and obtain the score ONLY for the final results, not for all. I do something like this:;



Criteria c = filter.processCriteria(fullTextSession.createCriteria(Page.class,"p"));

Criteria c2 = filter.processCriteria(fullTextSession.createCriteria(Page.class));



total = fullTextSession.createFullTextQuery(luceneQuery)
.setCriteriaQuery(c2).list().size();



List pages = fullTextSession
.createFullTextQuery(luceneQuery)
.setCriteriaQuery(c)
.setFirstResult(startIndex-1)
.setMaxResults(count)
.list();


I cannot use a ResultTransformer here, because if I use it, my criteria filter was away, and I get all the results retrieved from the index. It's my main problem.

Thank you in advance!

PD: I suggest to include a [CODE] tag here in order to paste these code snippets. Thanks.
emmanuel.bernard (101) [Avatar] Offline
#13
Re: Adding Lucene Score
Using a Criteria to restrict further the results is not supported. We explain that in chapter 6. There are other ways around including pushing the necessary restriction data into the index using special bridges (check chapter 4) or using Lucene filters (check chapter smilie
dafe52 (3) [Avatar] Offline
#14
Re: Adding Lucene Score
Thank you. I have to deliver my project in few days and probably I won't read the book until I have delivered it...

Probably it's not the thread but I have strange thing to create FSDirectory base index directory....

If I put <indexBase>index</indexBase>, it always creates the directory outside of my classpath... how can I create the index base inside of my webapp without specify it explicity, in order to copy it into the war file
emmanuel.bernard (101) [Avatar] Offline
#15
Re: Adding Lucene Score
The directory is relative to where the JVM has been started. So you need to put a relative path from there to where you want to put your indexes.