Hi experts,
I have an urgent and very detailed question regarding Hibernate Search/Lucene. My question is about the scoring.. but let me first explain my domain-model:
There is a Person class having a one-to-many relationship to a Job class. This Job class has a many-to-many relationship to a Function class.
Here the code snippets
Person class
Code:
@Entity
@Name("person")
@Table(name = "person", schema = "public")
@Indexed
public class Person implements java.io.Serializable {
...
@IndexedEmbedded(depth = 4)
private Collection<Job> jobs = new ArrayList<Job>();
@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE,
CascadeType.REFRESH, CascadeType.REMOVE }, fetch = FetchType.LAZY, mappedBy = "person")
public Collection<Job> getJobs() {
return jobs;
}
...
}
Job class:
Code:
@Entity
@Name("job")
@Table(name = "job", schema = "public")
@Indexed
public class Job implements java.io.Serializable {
...
@ContainedIn
private Person person;
@IndexedEmbedded(depth = 2)
private Collection<Function> functions = new ArrayList<Function>();
@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE,
CascadeType.REFRESH }, fetch = FetchType.LAZY)
@JoinTable(name = "job_funktion", schema = "public", joinColumns = { @JoinColumn(name = "job_id") }, inverseJoinColumns = { @JoinColumn(name = "function_id") })
public Collection<Function> getFunctions() {
return this.functions;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "person_id")
public Person getPerson() {
return this.person;
}
...
}
Function class:
Code:
@Entity
@Table(name = "funktion", schema = "public")
@Embeddable
@Indexed
public class Function implements java.io.Serializable {
...
@FieldBridge(impl = LongBridge.class)
private Long functioncode;
private Collection<Job> jobs;
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "job_function", schema = "public", joinColumns = { @JoinColumn(name = "function_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "job_id", nullable = false, updatable = false) })
@ContainedIn
public Collection<Job> getJobs() {
return this.jobs;
}
@Column(name = "functioncode")
public Long getFunctioncode() {
return this.functioncode;
}
...
}
I want to query and score persons regarding their jobs function-codes.
The important thing concerning the result scoring is that I do not care how often the search term is contained in the document. I also do not care how long the queried field is. All I want to know is if the search term (functioncode) is contained in the document or not. So I created my own Similarity class returning 1 for every factor in the similarity scoring formula (term-frequency, lengthNorm, etc), so I get the scores as expected.
For example I want to search all persons having jobs with functioncodes 510 or 520 or 530
My Lucene query is:
Code:
person.jobs.functions.functioncode:(510 520 530)^1.0
The returned result set of Hibernate Search is correct, but the scoring is not!
For example, persons having all 3 functioncodes get a higher score (100%) than persons with only one function code (50%).
What I want is that all persons get 100% even if they match only one of the 3 functioncodes. I though this should be solved by returning 1 for the tf- and lengthNorm method in my Similarty class....
I know that this question is really specific but maybe one of the Hibernate/Lucene experts can give me some hints. Any help would be appreciated.
Thanks,
Alexander