I am using a LuceneQuery to do a spatial search to find locations within a certain lat and long. This works as expected. I want to add to the search by filtering all locations that have a particular item in their store. I am trying to use @FullTextFilterDefs but am not sure how I can filter on the properties of Item.class when I set the enableFullTextFilter("filt").setParameter("", "").
Here is my configuration. I have condensed the code for simplicity sake.
Code:
@Entity
@Indexed
@Spatial
@FullTextFilterDefs( {
@FullTextFilterDef(name = "filt", impl = filter.class)})
public class Location {
private Long id;
private List<Item>items;
... all other fields declared
@IndexEmbedded
@OneToMany(mappedBy="location")
public List<Item> getItems() {
return this.items;
}
@Entity
@Indexed
public class Item {
... all other fields
@ContainedIn
@ManyToOne
public Location getLocation() {
return location;
}
public class LocationLoader {
public List<Location> load(Item i) {
List<Location> result = new ArrayList<Location>();
//setup query builder .....
org.apache.lucene.search.Query luceneQuery = builder.spatial()
.onCoordinates(Location.class.getName())
.within(radius, Unit.KM)
.ofLatitude(lat)
.andLongitude(lon)
.createQuery();
final FullTextQuery fullTextQuery = fullTextSession.createFullTextQuery(luceneQuery, Location.class);
//filter locations that have a particular item
fullTextQuery.enableFullTextFilter("filt").setParameter("item.itemRef", i.getItemRef() ); //<- how can you filter on a field from the Item object?
result.addAll(fullTextQuery.list());
return result;
}
}