-->
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.  [ 5 posts ] 
Author Message
 Post subject: GeoHashDistanceFilter Not working with Sub Classes
PostPosted: Mon Sep 20, 2010 9:39 am 
Newbie

Joined: Tue Sep 23, 2003 7:02 am
Posts: 16
I am using Hibernate 3 Hibernate Search 3.2 Final and Lucene 2.9.2

I get an exception (java.lang.IllegalArgumentException: null iterator "please see below") when using the GeoHashDistanceFilter only when I provide the Hibernate super pojo class but not the Subclass. I was under the impression that Filters are not related to the indexed class specified
am I wrong?

Even so why does Lucene throw the exception?

Is this a Hibernate or Lucene bug?

thanks in advance for any help with this. If I do not resolve this I will have to make a significant change to my model and code.

The only ref on the internet I can find that in anyway relates to this problem can be found here

https://issues.apache.org/jira/browse/LUCENE-2613

Code:
        // When I pass the super class I get the exception
        fullTextQuery = fullTextSession.createFullTextQuery(query, JobSpec.class);

        // When I pass the sub class I do not get the exception
        fullTextQuery = fullTextSession.createFullTextQuery(query, ContractJobSpec.class);

        Filter filter = getPostCodeFilter(critPostcode, query);
           
        if(filter != null)
        {
          fullTextQuery.setFilter(filter);
         }
     

    private Filter getPostCodeFilter(CritPostcode critPostcode, Query query)
    {
        GeoHashDistanceFilter geoHashDistanceFilter = null;

        if(critPostcode != null)
        {
            String postCode = critPostcode.getPostcode();
            String outcode = OutcodeUtil.getOutcode(postCode);
            OutcodeLatLng outcodeLatLng = outcodeLatLngDAO.getByExternalID(outcode);

            geoHashDistanceFilter = new GeoHashDistanceFilter(new QueryWrapperFilter(query), outcodeLatLng.getLat(), outcodeLatLng.getLng(), critPostcode.getMaxDistance(), geoHashProperty);
        }

        return geoHashDistanceFilter;
    }


Code:
java.lang.IllegalArgumentException: null iterator
        at org.apache.lucene.search.FilteredDocIdSetIterator.<init>(FilteredDocIdSetIterator.java:38)
        at org.apache.lucene.search.FilteredDocIdSet$1.<init>(FilteredDocIdSet.java:72)
        at org.apache.lucene.search.FilteredDocIdSet.iterator(FilteredDocIdSet.java:71)
        at org.apache.lucene.search.IndexSearcher.searchWithFilter(IndexSearcher.java:279)
        at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:254)
        at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:173)
        at org.apache.lucene.search.Searcher.search(Searcher.java:181)
        at org.hibernate.search.query.QueryHits.updateTopDocs(QueryHits.java:107)
        at org.hibernate.search.query.QueryHits.<init>(QueryHits.java:68)
        at org.hibernate.search.query.QueryHits.<init>(QueryHits.java:58)
        at org.hibernate.search.query.FullTextQueryImpl.getQueryHits(FullTextQueryImpl.java:405)
        at org.hibernate.search.query.FullTextQueryImpl.list(FullTextQueryImpl.java:326)


Top
 Profile  
 
 Post subject: Re: GeoHashDistanceFilter Not working with Sub Classes
PostPosted: Tue Sep 21, 2010 6:08 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Could you also post the code with the annotated classes? The stack trace seems to come out of Lucene, but it seems strange that it depends on the index you are trying to search. Maybe you could even isolate a (junit) testcase. That would be awesome.

--Hardy


Top
 Profile  
 
 Post subject: Re: GeoHashDistanceFilter Not working with Sub Classes
PostPosted: Tue Sep 21, 2010 12:15 pm 
Newbie

Joined: Tue Sep 23, 2003 7:02 am
Posts: 16
Hi

Thanks for the reply.

The web application I am writing is very large. I have a number of junit tests but in order for you to run them it would mean downloading it from my SVN server.

I have thought about writing a separate small application that simulates the problem with only two objects but this will take me probably 1/2 day to a day to complete in the time being here is all the code I think is relevant.

Only when I invoke the GeoHashDistanceFilter does the exception get thrown and only when I specify the super class or all three of the subclass but not if I specify one sub class. {Maybe because then there is a result instead of no results???? what do you think}

Code:

// Generated 13-Feb-2009 12:56:46 by Hibernate Tools 3.2.2.GA

import org.hibernate.search.annotations.Indexed;

/**
* ContractJobSpec generated by hbm2java
*/
@Indexed
public class ContractJobSpec extends JobSpec implements java.io.Serializable {

    private Short numberOfWeeks;

    public ContractJobSpec() {
    }

    /**
     * @return the numberOfWeeks
     */
    public Short getNumberOfWeeks() {
        return numberOfWeeks;
    }

    /**
     * @param numberOfWeeks the numberOfWeeks to set
     */
    public void setNumberOfWeeks(Short numberOfWeeks) {
        this.numberOfWeeks = numberOfWeeks;
    }
}


package com.tm.persistence;

// Generated 09-Mar-2009 17:58:06 by Hibernate Tools 3.2.2.GA
import com.tm.lucene.bridges.JobSpecMBridge;
import com.tm.lucene.bridges.JobSpecMTBridge;
import com.tm.lucene.bridges.JobSpecSBridge;
import com.tm.lucene.bridges.JobSpecSMBridge;
import com.tm.lucene.bridges.JobSpecSMTBridge;
import com.tm.lucene.bridges.JobSpecSTBridge;
import com.tm.lucene.bridges.JobSpecTBridge;
import com.tm.util.WorkPatternBridge;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Transient;
import org.apache.lucene.spatial.geohash.GeoHashUtils;
import org.hibernate.search.annotations.ClassBridge;
import org.hibernate.search.annotations.ClassBridges;
import org.hibernate.search.annotations.DateBridge;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Store;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.FieldBridge;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;
import org.hibernate.search.annotations.Resolution;

/**
* JobSpec generated by hbm2java
*/

public class JobSpec implements java.io.Serializable {

    @DocumentId
    private Integer idjobSpec;
    private User userByCreatedBy;
    private User userByModifiedBy;
    @IndexedEmbedded
    private EmployerUser employerUser;
    private Department department;
    @IndexedEmbedded
    private EduLevel eduLevel;
    private Address address;
    @IndexedEmbedded
    private JobType jobType;
    private SectorManagementTitle sectorManagementTitle;
    @Field(index=Index.UN_TOKENIZED, store=Store.YES)
    private String status;
    private BigDecimal maxWageOffer;
    private String wageTimeUnit;
    @Field(index=Index.TOKENIZED, store=Store.NO)
    private String jobDescription;
    private Short numberAvailable;
    private Short positionsFilled;
    private Short hoursPerWeek;
    @Field(index=Index.UN_TOKENIZED, store=Store.YES)
    @DateBridge(resolution=Resolution.DAY)
    private Date startDateFrom;
    private Date startDateTo;
    @Field(index=Index.UN_TOKENIZED, store=Store.YES)
    @DateBridge(resolution=Resolution.DAY)
    private Date endDate;
    @Field(index=Index.UN_TOKENIZED, store=Store.YES)
    @FieldBridge(impl = WorkPatternBridge.class)
    private Integer workPattern;
    @Field(index=Index.UN_TOKENIZED, store=Store.YES)
    private Boolean fiveOrMoreGcses;
    private Boolean mustHaveFiveMoreGcses;
    private Short distanceFromJob;
    private Boolean mustHaveDistanceFromJob;
    private Short ucasPoints;
    private Short penaltyPoints;
    private Date dateCreated;
    private Date dateModified;
    private String externalId;
    private Boolean archive;
    private Short ver;
    @Field(index=Index.UN_TOKENIZED, store=Store.YES)
    private Boolean publicDisplay;
    @Field(index=Index.UN_TOKENIZED, store=Store.YES)
    @DateBridge(resolution=Resolution.DAY)
    private Date datePosted;
    @Field(index=Index.UN_TOKENIZED, store=Store.YES)
    @DateBridge(resolution=Resolution.DAY)
    private Date endPostDate;
    private Short numberOfWeeks;
    @Field(index=Index.UN_TOKENIZED, store=Store.YES)
    private Integer minAverageEmployeeFeedback;

    @IndexedEmbedded
    private Set<JobSpecEduQual> jobSpecEduQuals = new HashSet(0);

    @IndexedEmbedded
    private Set<JobSpecProfQual> jobSpecProfQuals = new HashSet(0);
   
    private Set jobs = new HashSet(0);

    @IndexedEmbedded
    private Set<JobSpecSkill> jobSpecSkills = new HashSet(0);
   
    private Set jobSpecActions = new HashSet(0);
    private Set<JobOffer> jobOffers = new HashSet<JobOffer>(0);
    private Set<JobInterview> jobInterviews = new HashSet<JobInterview>(0);
    private Set<JobApplication> jobApplications = new HashSet<JobApplication>(0);


    @IndexedEmbedded
    private Set<JobSpecExperience> jobSpecExperiences = new HashSet(0);

    private Set employeeUserCandidateGroups = new HashSet(0);
    private Set jobSpecDrivingLicenses = new HashSet(0);

    @IndexedEmbedded
    private Set<JobSpecTestResult> jobSpecTestResults = new HashSet(0);

    public JobSpec() {
    }

    @Transient
    @Field(index = Index.UN_TOKENIZED, store = Store.YES, name = "geohash")
    public String getGeohash() {

        String geohash = null;
        Address address = getAddress();

        if(address != null)
        {
            OutcodeLatLng outcodeLatLng = address.getOutcodeLatLng();

            if(outcodeLatLng != null)
            {
                geohash = GeoHashUtils.encode(outcodeLatLng.getLat(), outcodeLatLng.getLng());
            }

        }

        return geohash;
    }

    public Integer getIdjobSpec() {
        return this.idjobSpec;
    }

    public void setIdjobSpec(Integer idjobSpec) {
        this.idjobSpec = idjobSpec;
    }

    public User getUserByCreatedBy() {
        return this.userByCreatedBy;
    }

    public void setUserByCreatedBy(User userByCreatedBy) {
        this.userByCreatedBy = userByCreatedBy;
    }

    public User getUserByModifiedBy() {
        return this.userByModifiedBy;
    }

    public void setUserByModifiedBy(User userByModifiedBy) {
        this.userByModifiedBy = userByModifiedBy;
    }

    public EmployerUser getEmployerUser() {
        return this.employerUser;
    }

    public void setEmployerUser(EmployerUser employerUser) {
        this.employerUser = employerUser;
    }

    public Department getDepartment() {
        return this.department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

    public String getStatus() {
        return this.status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public BigDecimal getMaxWageOffer() {
        return this.maxWageOffer;
    }

    public void setMaxWageOffer(BigDecimal maxWageOffer) {
        if(maxWageOffer != null)
        {
            this.maxWageOffer = maxWageOffer.setScale(2, BigDecimal.ROUND_HALF_UP);
        }
    }

    public String getJobDescription() {
        return this.jobDescription;
    }

    public void setJobDescription(String jobDescription) {
        this.jobDescription = jobDescription;
    }

    public Short getNumberAvailable() {
        return this.numberAvailable;
    }

    public void setNumberAvailable(Short numberAvailable) {
        this.numberAvailable = numberAvailable;
    }

    public Short getHoursPerWeek() {
        return this.hoursPerWeek;
    }

    public void setHoursPerWeek(Short hoursPerWeek) {
        this.hoursPerWeek = hoursPerWeek;
    }

    public Date getStartDateFrom() {
        return this.startDateFrom;
    }

    public void setStartDateFrom(Date startDateFrom) {
        this.startDateFrom = startDateFrom;
    }

    public Date getStartDateTo() {
        return this.startDateTo;
    }

    public void setStartDateTo(Date startDateTo) {
        this.startDateTo = startDateTo;
    }

    public Date getEndDate() {
        return this.endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public Integer getWorkPattern() {
        return this.workPattern;
    }

    public void setWorkPattern(Integer workPattern) {
        this.workPattern = workPattern;
    }

    public Date getDateCreated() {
        return this.dateCreated;
    }

    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }

    public Date getDateModified() {
        return this.dateModified;
    }

    public void setDateModified(Date dateModified) {
        this.dateModified = dateModified;
    }

    public String getExternalId() {
        return this.externalId;
    }

    public void setExternalId(String externalId) {
        this.externalId = externalId;
    }

    public Boolean getArchive() {
        return this.archive;
    }

    public void setArchive(Boolean archive) {
        this.archive = archive;
    }

    public Short getVer() {
        return this.ver;
    }

    public void setVer(Short ver) {
        this.ver = ver;
    }

    public Set<JobSpecEduQual> getJobSpecEduQuals() {
        return this.jobSpecEduQuals;
    }

    public void setJobSpecEduQuals(Set<JobSpecEduQual> jobSpecEduQuals) {
        this.jobSpecEduQuals = jobSpecEduQuals;
    }

    public Set<JobSpecProfQual> getJobSpecProfQuals() {
        return this.jobSpecProfQuals;
    }

    public void setJobSpecProfQuals(Set<JobSpecProfQual> jobSpecProfQuals) {
        this.jobSpecProfQuals = jobSpecProfQuals;
    }

    public Set getJobs() {
        return this.jobs;
    }

    public void setJobs(Set jobs) {
        this.jobs = jobs;
    }

    public Set<JobSpecSkill> getJobSpecSkills() {
        return this.jobSpecSkills;
    }

    public void setJobSpecSkills(Set<JobSpecSkill> jobSpecSkills) {
        this.jobSpecSkills = jobSpecSkills;
    }

    public Set<JobSpecExperience> getJobSpecExperiences() {
        return this.jobSpecExperiences;
    }

    public void setJobSpecExperiences(Set<JobSpecExperience> jobSpecExperiences) {
        this.jobSpecExperiences = jobSpecExperiences;
    }

    /**
     * @return the publicDisplay
     */
    public Boolean getPublicDisplay() {
        return publicDisplay;
    }

    /**
     * @param publicDisplay the publicDisplay to set
     */
    public void setPublicDisplay(Boolean publicDisplay) {
        this.publicDisplay = publicDisplay;
    }

    /**
     * @return the employeeUserCandidateGroups
     */
    public Set getEmployeeUserCandidateGroups() {
        return employeeUserCandidateGroups;
    }

    /**
     * @param employeeUserCandidateGroups the employeeUserCandidateGroups to set
     */
    public void setEmployeeUserCandidateGroups(Set employeeUserCandidateGroups) {
        this.employeeUserCandidateGroups = employeeUserCandidateGroups;
    }

    /**
     * @return the jobSpecDrivingLicenses
     */
    public Set getJobSpecDrivingLicenses() {
        return jobSpecDrivingLicenses;
    }

    /**
     * @param jobSpecDrivingLicenses the jobSpecDrivingLicenses to set
     */
    public void setJobSpecDrivingLicenses(Set jobSpecDrivingLicenses) {
        this.jobSpecDrivingLicenses = jobSpecDrivingLicenses;
    }

    /**
     * @return the fiveOrMoreGcses
     */
    public Boolean getFiveOrMoreGcses() {
        return fiveOrMoreGcses;
    }

    /**
     * @param fiveOrMoreGcses the fiveOrMoreGcses to set
     */
    public void setFiveOrMoreGcses(Boolean fiveOrMoreGcses) {
        this.fiveOrMoreGcses = fiveOrMoreGcses;
    }

    /**
     * @return the ucasPoints
     */
    public Short getUcasPoints() {
        return ucasPoints;
    }

    /**
     * @param ucasPoints the ucasPoints to set
     */
    public void setUcasPoints(Short ucasPoints) {
        this.ucasPoints = ucasPoints;
    }

    /**
     * @return the penaltyPoints
     */
    public Short getPenaltyPoints() {
        return penaltyPoints;
    }

    /**
     * @param penaltyPoints the penaltyPoints to set
     */
    public void setPenaltyPoints(Short penaltyPoints) {
        this.penaltyPoints = penaltyPoints;
    }

    /**
     * @return the jobSpecActions
     */
    public Set getJobSpecActions() {
        return jobSpecActions;
    }

    /**
     * @param jobSpecActions the jobSpecActions to set
     */
    public void setJobSpecActions(Set jobSpecActions) {
        this.jobSpecActions = jobSpecActions;
    }

    /**
     * @return the eduLevel
     */
    public EduLevel getEduLevel() {
        return eduLevel;
    }

    /**
     * @param eduLevel the eduLevel to set
     */
    public void setEduLevel(EduLevel eduLevel) {
        this.eduLevel = eduLevel;
    }

    /**
     * @return the address
     */
    public Address getAddress() {
        return address;
    }

    /**
     * @param address the address to set
     */
    public void setAddress(Address address) {
        this.address = address;
    }

    /**
     * @return the wageTimeUnit
     */
    public String getWageTimeUnit() {
        return wageTimeUnit;
    }

    /**
     * @param wageTimeUnit the wageTimeUnit to set
     */
    public void setWageTimeUnit(String wageTimeUnit) {
        this.wageTimeUnit = wageTimeUnit;
    }

    /**
     * @return the datePosted
     */
    public Date getDatePosted() {
        return datePosted;
    }

    /**
     * @param datePosted the datePosted to set
     */
    public void setDatePosted(Date datePosted) {
        this.datePosted = datePosted;
    }

    /**
     * @return the endPostDate
     */
    public Date getEndPostDate() {
        return endPostDate;
    }

    /**
     * @param endPostDate the endPostDate to set
     */
    public void setEndPostDate(Date endPostDate) {
        this.endPostDate = endPostDate;
    }

    /**
     * @return the jobType
     */
    public JobType getJobType() {
        return jobType;
    }

    /**
     * @param jobType the jobType to set
     */
    public void setJobType(JobType jobType) {
        this.jobType = jobType;
    }

    /**
     * @return the sectorManagementTitle
     */
    public SectorManagementTitle getSectorManagementTitle() {
        return sectorManagementTitle;
    }

    /**
     * @param sectorManagementTitle the sectorManagementTitle to set
     */
    public void setSectorManagementTitle(SectorManagementTitle sectorManagementTitle) {
        this.sectorManagementTitle = sectorManagementTitle;
    }

    /**
     * @return the numberOfWeeks
     */
    public Short getNumberOfWeeks() {
        return numberOfWeeks;
    }

    /**
     * @param numberOfWeeks the numberOfWeeks to set
     */
    public void setNumberOfWeeks(Short numberOfWeeks) {
        this.numberOfWeeks = numberOfWeeks;
    }

    /**
     * @return the mustHaveFiveMoreGcses
     */
    public Boolean getMustHaveFiveMoreGcses() {
        return mustHaveFiveMoreGcses;
    }

    /**
     * @param mustHaveFiveMoreGcses the mustHaveFiveMoreGcses to set
     */
    public void setMustHaveFiveMoreGcses(Boolean mustHaveFiveMoreGcses) {
        this.mustHaveFiveMoreGcses = mustHaveFiveMoreGcses;
    }

    /**
     * @return the distanceFromJob
     */
    public Short getDistanceFromJob() {
        return distanceFromJob;
    }

    /**
     * @param distanceFromJob the distanceFromJob to set
     */
    public void setDistanceFromJob(Short distanceFromJob) {
        this.distanceFromJob = distanceFromJob;
    }

    /**
     * @return the mustHaveDistanceFromJob
     */
    public Boolean getMustHaveDistanceFromJob() {
        return mustHaveDistanceFromJob;
    }

    /**
     * @param mustHaveDistanceFromJob the mustHaveDistanceFromJob to set
     */
    public void setMustHaveDistanceFromJob(Boolean mustHaveDistanceFromJob) {
        this.mustHaveDistanceFromJob = mustHaveDistanceFromJob;
    }

    /**
     * @return the jobOffers
     */
    public Set<JobOffer> getJobOffers() {
        return jobOffers;
    }

    /**
     * @param jobOffers the jobOffers to set
     */
    public void setJobOffers(Set<JobOffer> jobOffers) {
        this.jobOffers = jobOffers;
    }

    /**
     * @return the jobInterviews
     */
    public Set<JobInterview> getJobInterviews() {
        return jobInterviews;
    }

    /**
     * @param jobInterviews the jobInterviews to set
     */
    public void setJobInterviews(Set<JobInterview> jobInterviews) {
        this.jobInterviews = jobInterviews;
    }

    /**
     * @return the jobApplications
     */
    public Set<JobApplication> getJobApplications() {
        return jobApplications;
    }

    /**
     * @param jobApplications the jobApplications to set
     */
    public void setJobApplications(Set<JobApplication> jobApplications) {
        this.jobApplications = jobApplications;
    }

    /**
     * @return the minAverageEmployeeFeedback
     */
    public Integer getMinAverageEmployeeFeedback() {
        return minAverageEmployeeFeedback;
    }

    /**
     * @param minAverageEmployeeFeedback the minAverageEmployeeFeedback to set
     */
    public void setMinAverageEmployeeFeedback(Integer minAverageEmployeeFeedback) {
        this.minAverageEmployeeFeedback = minAverageEmployeeFeedback;
    }

    /**
     * @return the positionsFilled
     */
    public Short getPositionsFilled() {
        return positionsFilled;
    }

    /**
     * @param positionsFilled the positionsFilled to set
     */
    public void setPositionsFilled(Short positionsFilled) {
        this.positionsFilled = positionsFilled;
    }

    /**
     * @return the jobSpecTestResults
     */
    public Set<JobSpecTestResult> getJobSpecTestResults() {
        return jobSpecTestResults;
    }

    /**
     * @param jobSpecTestResults the jobSpecTestResults to set
     */
    public void setJobSpecTestResults(Set<JobSpecTestResult> jobSpecTestResults) {
        this.jobSpecTestResults = jobSpecTestResults;
    }

}

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 09-Mar-2009 17:58:07 by Hibernate Tools 3.2.2.GA -->
<hibernate-mapping>
  <class name="com.tm.persistence.JobSpec" table="job_spec">
    <id name="idjobSpec" type="java.lang.Integer">
      <column name="idjob_spec"/>
      <generator class="native"/>
    </id>
    <discriminator column="jobSpecDiscriminator" type="string"/>
    <version column="ver" name="ver" type="java.lang.Short"/>
    <many-to-one class="com.tm.persistence.JobType" fetch="select" lazy="false" name="jobType">
      <column name="job_type_idjob_type" not-null="true"/>
    </many-to-one>
    <many-to-one class="com.tm.persistence.SectorManagementTitle" fetch="select" lazy="false" name="sectorManagementTitle">
      <column name="sector_management_title_idsector_management_title" not-null="true"/>
    </many-to-one>
    <many-to-one class="com.tm.persistence.User" fetch="select" name="userByCreatedBy">
      <column name="createdBy"/>
    </many-to-one>
    <many-to-one class="com.tm.persistence.User" fetch="select" name="userByModifiedBy">
      <column name="modifiedBy"/>
    </many-to-one>
    <many-to-one class="com.tm.persistence.EmployerUser" fetch="select" lazy="false" name="employerUser">
      <column name="employer_user_idemployer_user" not-null="true"/>
    </many-to-one>
    <many-to-one class="com.tm.persistence.Department" fetch="select" name="department">
      <column name="department_iddepartment"/>
    </many-to-one>
    <many-to-one class="com.tm.persistence.EduLevel" fetch="select" name="eduLevel">
      <column name="edu_level_idedu_level" not-null="false"/>
    </many-to-one>
    <many-to-one class="com.tm.persistence.Address" fetch="select" lazy="false" name="address">
      <column name="address_idaddress"/>
    </many-to-one>
    <property name="status" type="string">
      <column length="31" name="status" not-null="true"/>
    </property>
    <property name="maxWageOffer" type="big_decimal">
      <column name="maxWageOffer" not-null="true" precision="9"/>
    </property>
    <property name="wageTimeUnit" type="string">
      <column name="wageTimeUnit" not-null="true"/>
    </property>
    <property name="jobDescription" type="string">
      <column name="jobDescription" not-null="true"/>
    </property>
    <property name="numberAvailable" type="short">
      <column name="numberAvailable" not-null="true"/>
    </property>
    <property name="positionsFilled" type="short">
      <column name="positionsFilled" not-null="true"/>
    </property>
    <property name="hoursPerWeek" type="short">
      <column name="hoursPerWeek" not-null="true"/>
    </property>
    <property name="startDateFrom" type="java.util.Date">
      <column length="0" name="startDateFrom"/>
    </property>
    <property name="startDateTo" type="java.util.Date">
      <column length="0" name="startDateTo"/>
    </property>
    <property name="endDate" type="java.util.Date">
      <column length="0" name="endDate"/>
    </property>
    <property name="workPattern" type="java.lang.Integer">
      <column name="workPattern" not-null="true"/>
    </property>
    <property name="dateCreated" type="timestamp">
      <column length="0" name="dateCreated"/>
    </property>
    <property name="dateModified" type="timestamp">
      <column length="0" name="dateModified"/>
    </property>
    <property name="externalId" type="string">
      <column length="15" name="externalId"/>
    </property>
    <property name="archive" type="java.lang.Boolean">
      <column name="archive"/>
    </property>
    <property name="publicDisplay" type="java.lang.Boolean">
      <column name="publicDisplay"/>
    </property>
    <property name="datePosted" type="timestamp">
      <column length="0" name="datePosted"/>
    </property>
    <property name="endPostDate" type="timestamp">
      <column length="0" name="endPostDate"/>
    </property>
    <property name="fiveOrMoreGcses" type="java.lang.Boolean">
      <column name="fiveOrMoreGCSEs" not-null="true"/>
    </property>
    <property name="mustHaveFiveMoreGcses" type="java.lang.Boolean">
      <column name="mustHaveFiveMoreGcses"/>
    </property>
    <property name="distanceFromJob" type="java.lang.Short">
      <column name="distanceFromJob"/>
    </property>
    <property name="mustHaveDistanceFromJob" type="java.lang.Boolean">
      <column name="mustHaveDistanceFromJob"/>
    </property>
    <property name="ucasPoints" type="java.lang.Short">
      <column name="ucasPoints"/>
    </property>
    <property name="penaltyPoints" type="java.lang.Short">
      <column name="penaltyPoints"/>
    </property>
    <property name="minAverageEmployeeFeedback" type="java.lang.Integer">
      <column name="minAverageEmployeeFeedback"/>
    </property>
    <set inverse="true" name="jobSpecTestResults">
      <key>
        <column name="job_spec_idjob_spec" not-null="true"/>
      </key>
      <one-to-many class="com.tm.persistence.JobSpecTestResult"/>
    </set>
    <set inverse="true" name="jobSpecEduQuals">
      <key>
        <column name="job_spec_idjob_spec" not-null="true"/>
      </key>
      <one-to-many class="com.tm.persistence.JobSpecEduQual"/>
      <filter condition=":archive = archive" name="JobSpecJobSpecEduQualsArchiveFilter"/>
    </set>
    <set inverse="true" name="jobSpecProfQuals">
      <key>
        <column name="job_spec_idjob_spec" not-null="true"/>
      </key>
      <one-to-many class="com.tm.persistence.JobSpecProfQual"/>
      <filter condition=":archive = archive" name="JobSpecJobSpecProfQualsArchiveFilter"/>
    </set>
    <set inverse="true" name="jobs">
      <key>
        <column name="job_spec_idjob_spec" not-null="true"/>
      </key>
      <one-to-many class="com.tm.persistence.Job"/>
      <filter condition=":status = status" name="JobSpecJobsStatusFilter"/>
      <filter condition=":archive = archive" name="JobSpecJobsArchiveFilter"/>
    </set>
    <set inverse="true" name="jobSpecSkills">
      <key>
        <column name="job_spec_idjob_spec"/>
      </key>
      <one-to-many class="com.tm.persistence.JobSpecSkill"/>
      <filter condition=":archive = archive" name="JobSpecJobSpecSkillsArchiveFilter"/>
    </set>
    <set inverse="true" name="jobSpecActions">
      <key>
        <column name="job_spec_idjob_spec" not-null="true"/>
      </key>
      <one-to-many class="com.tm.persistence.JobSpecAction"/>
      <filter condition=":archive = archive" name="JobSpecJobSpecActionsArchiveFilter"/>
      <filter condition=":status = status" name="JobSpecJobSpecActionsStatusFilter"/>
      <filter condition=":jobActionDiscriminator = jobActionDiscriminator" name="JobSpecJobSpecActionsDiscriminatorFilter"/>
    </set>
    <set inverse="true" name="jobOffers">
      <key>
        <column name="job_spec_idjob_spec" not-null="true"/>
      </key>
      <one-to-many class="com.tm.persistence.JobOffer"/>
    </set>
    <set inverse="true" name="jobInterviews">
      <key>
        <column name="job_spec_idjob_spec" not-null="true"/>
      </key>
      <one-to-many class="com.tm.persistence.JobInterview"/>
    </set>
    <set inverse="true" name="jobApplications">
      <key>
        <column name="job_spec_idjob_spec" not-null="true"/>
      </key>
      <one-to-many class="com.tm.persistence.JobApplication"/>
    </set>
    <set inverse="true" name="jobSpecExperiences" order-by="idexperience">
      <key>
        <column name="job_spec_idjob_spec" not-null="true"/>
      </key>
      <one-to-many class="com.tm.persistence.JobSpecExperience"/>
      <filter condition=":archive = archive" name="JobSpecJobSpecExperiencesArchiveFilter"/>
    </set>
    <set inverse="true" name="employeeUserCandidateGroups">
      <key>
        <column name="job_spec_idjob_spec" not-null="true"/>
      </key>
      <one-to-many class="com.tm.persistence.EmployeeUserCandidateGroup"/>
      <filter condition=":archive = archive" name="JobSpecEmployeeUserCandidateGroupsArchiveFilter"/>
    </set>
    <set inverse="true" name="jobSpecDrivingLicenses">
      <key>
        <column name="job_spec_idjob_spec" not-null="true"/>
      </key>
      <one-to-many class="com.tm.persistence.JobSpecDrivingLicense"/>
      <filter condition=":archive = archive" name="JobSpecJobSpecDrivingLicensesArchiveFilter"/>
    </set>
    <subclass discriminator-value="ContractJobSpec" name="com.tm.persistence.ContractJobSpec">
      <property name="numberOfWeeks" type="short">
        <column name="numberOfWeeks" not-null="true"/>
      </property>
    </subclass>
    <subclass discriminator-value="PermanentJobSpec" name="com.tm.persistence.PermanentJobSpec">
        </subclass>
    <subclass discriminator-value="VolunteerJobSpec" name="com.tm.persistence.VolunteerJobSpec">
        </subclass>
    <!-- Class Level Filters -->
    <filter condition=":archive = archive" name="JobSpecArchiveFilter"/>
  </class>
  <!-- Filters Definitions -->
  <!-- Archive Filters Definitions -->
  <filter-def name="JobSpecArchiveFilter">
    <filter-param name="archive" type="java.lang.Boolean"/>
  </filter-def>
  <filter-def name="JobSpecJobSpecSkillsArchiveFilter">
    <filter-param name="archive" type="java.lang.Boolean"/>
  </filter-def>
  <filter-def name="JobSpecEmployeeUserCandidateGroupsArchiveFilter">
    <filter-param name="archive" type="java.lang.Boolean"/>
  </filter-def>
  <filter-def name="JobSpecJobSpecEduQualsArchiveFilter">
    <filter-param name="archive" type="java.lang.Boolean"/>
  </filter-def>
  <filter-def name="JobSpecJobSpecProfQualsArchiveFilter">
    <filter-param name="archive" type="java.lang.Boolean"/>
  </filter-def>
  <filter-def name="JobSpecJobSpecDrivingLicensesArchiveFilter">
    <filter-param name="archive" type="java.lang.Boolean"/>
  </filter-def>
  <filter-def name="JobSpecJobSpecExperiencesArchiveFilter">
    <filter-param name="archive" type="java.lang.Boolean"/>
  </filter-def>
  <filter-def name="JobSpecJobsStatusFilter">
    <filter-param name="status" type="java.lang.String"/>
  </filter-def>
  <filter-def name="JobSpecJobsArchiveFilter">
    <filter-param name="archive" type="java.lang.Boolean"/>
  </filter-def>
  <filter-def name="JobSpecJobSpecActionsArchiveFilter">
    <filter-param name="archive" type="java.lang.Boolean"/>
  </filter-def>
  <filter-def name="JobSpecJobSpecActionsDiscriminatorFilter">
    <filter-param name="jobActionDiscriminator" type="string"/>
  </filter-def>
  <filter-def name="JobSpecJobSpecActionsStatusFilter">
    <filter-param name="status" type="string"/>
  </filter-def>
</hibernate-mapping>


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package com.tm.service.core.helper.impl.search;

import com.tm.persistence.ContractJobSpec;
import com.tm.persistence.JobSpec;
import com.tm.persistence.PermanentJobSpec;
import com.tm.persistence.VolunteerJobSpec;
import com.tm.service.core.helper.JobSpecSearchService;

/**
*
* @author lee
*/
public class JobSpecSearchServiceImpl extends AbstractSearchServiceImpl<JobSpec> implements JobSpecSearchService{

    @Override
    public Class[] getResultClasses() {
        // I tried this same problem
        /*Class[] classes = new Class[3];
        classes[0] = ContractJobSpec.class;
        classes[1] = PermanentJobSpec.class;
        classes[2] = VolunteerJobSpec.class;*/

        Class[] classes = new Class[1];
        classes[0] = JobSpec.class;
        return classes;
    }

}

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package com.tm.service.core.helper.impl.search;

import com.tm.dao.core.OutcodeLatLngDAO;
import com.tm.dao.core.bean.PageInfo;
import com.tm.persistence.OutcodeLatLng;
import com.tm.persistence.search.CritAllSearch;
import com.tm.persistence.search.CritKeyWords;
import com.tm.persistence.search.CritPostcode;
import com.tm.service.core.helper.SearchQueryBuilder;
import com.tm.service.exception.ServiceRuntimeException;
import com.tm.util.OutcodeUtil;
import java.util.List;
import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.queryParser.MultiFieldQueryParser;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryWrapperFilter;
import org.apache.lucene.spatial.geohash.GeoHashDistanceFilter;
import org.hibernate.Session;
import org.hibernate.search.FullTextQuery;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
*
* @author lee
*/
public abstract class AbstractSearchServiceImpl <T> extends HibernateDaoSupport
{
    private SearchQueryBuilder searchQueryBuilder;
    private OutcodeLatLngDAO outcodeLatLngDAO;
    private String geoHashProperty;

    public List<T> search(CritAllSearch critAllSearch, PageInfo pageInfo)
    {
        List results;
        FullTextQuery fullTextQuery = buildFullTextQuery(critAllSearch);

        if (pageInfo != null) {

            if(!pageInfo.isAllRecords())
            {
                fullTextQuery.setMaxResults(pageInfo.getPageSize());
                fullTextQuery.setFirstResult(pageInfo.getFirstRow());
                fullTextQuery.setFetchSize(pageInfo.getPageSize());
            }

            if (pageInfo.isGetMeSize())
            {
                pageInfo.setTotalSize(fullTextQuery.getResultSize());
            }

        }

        results = fullTextQuery.list();
        return results;
    }

    public Explanation explain(CritAllSearch critAllSearch, int documentID)
    {
        FullTextQuery fullTextQuery = buildFullTextQuery(critAllSearch);
        return fullTextQuery.explain(documentID);
    }


    private FullTextQuery buildFullTextQuery(CritAllSearch critAllSearch)
    {
        Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
        FullTextSession fullTextSession = Search.getFullTextSession(session);

        Query query = searchQueryBuilder.buildQuery(critAllSearch);

        FullTextQuery fullTextQuery = null;
       

        if(getResultClasses().length == 1)
        {
            fullTextQuery = fullTextSession.createFullTextQuery(query, getResultClasses()[0]);
        }

        if(getResultClasses().length == 3)
        {
            fullTextQuery = fullTextSession.createFullTextQuery(query, getResultClasses()[0], getResultClasses()[1], getResultClasses()[2]);
        }

        CritPostcode critPostcode = critAllSearch.getLocation();

        if(critPostcode != null && critPostcode.isUsed())
        {
            Filter filter = getPostCodeFilter(critPostcode, query);
           
            if(filter != null)
            {
                fullTextQuery.setFilter(filter);
            }
        }
       
        return fullTextQuery;
    }

    public void buildIndex(){

        try
        {
            FullTextSession fullTextSession = Search.getFullTextSession(getHibernateTemplate().getSessionFactory().getCurrentSession());
            fullTextSession.createIndexer().startAndWait();
        }
        catch(InterruptedException exc)
        {
            throw new ServiceRuntimeException(exc);
        }
    }

    public abstract Class[] getResultClasses();

    /**
     * @param searchQueryBuilder the searchQueryBuilder to set
     */
    public void setSearchQueryBuilder(SearchQueryBuilder searchQueryBuilder) {
        this.searchQueryBuilder = searchQueryBuilder;
    }

    private Filter getPostCodeFilter(CritPostcode critPostcode, Query query)
    {
        GeoHashDistanceFilter geoHashDistanceFilter = null;

        if(critPostcode != null)
        {
            String postCode = critPostcode.getPostcode();
            String outcode = OutcodeUtil.getOutcode(postCode);
            OutcodeLatLng outcodeLatLng = outcodeLatLngDAO.getByExternalID(outcode);

            geoHashDistanceFilter = new GeoHashDistanceFilter(new QueryWrapperFilter(query), outcodeLatLng.getLat(), outcodeLatLng.getLng(), critPostcode.getMaxDistance(), geoHashProperty);
        }

        return geoHashDistanceFilter;
    }

    /**
     * @param outcodeLatLngDAO the outcodeLatLngDAO to set
     */
    public void setOutcodeLatLngDAO(OutcodeLatLngDAO outcodeLatLngDAO) {
        this.outcodeLatLngDAO = outcodeLatLngDAO;
    }

    /**
     * @param geoHashProperty the geoHashProperty to set
     */
    public void setGeoHashProperty(String geoHashProperty) {
        this.geoHashProperty = geoHashProperty;
    }

}



Top
 Profile  
 
 Post subject: Re: GeoHashDistanceFilter Not working with Sub Classes
PostPosted: Wed Sep 22, 2010 2:22 pm 
Newbie

Joined: Tue Sep 23, 2003 7:02 am
Posts: 16
Hi Hardy

It seems that I was sent on a wild goose chase. I think and I have yet to confirm this but I suspect that my problem was related to an index corruption.

I went through the process of writing and isolated test which to my horror did not fail. I then deduced that if hibernate was doing its job correctly and Lucene was returning results then

the only issue could be the index itself.

It appears that rebuilding the index alone was not enough I had to delete the index from the disk and then rebuild it to solve the problem.

At this time I have not experienced the issue again. However it does worry me because I have experienced the same problem in my dev and staging environments.

It is likely to rear its ugly head again but at least if it does I can concentrate on the index and not the search.

Sorry to have waisted your time.

Lee


Top
 Profile  
 
 Post subject: Re: GeoHashDistanceFilter Not working with Sub Classes
PostPosted: Thu Sep 23, 2010 3:50 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Great. In fact I was going to ask you to narrow down your problem anyways. Turns out you did this already and hopefully solved your problem :)

--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.