-->
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: How to know which fields matched
PostPosted: Mon Aug 12, 2013 5:43 am 
Newbie

Joined: Thu Aug 08, 2013 6:36 am
Posts: 1
Hi there,

I am using Hibernate 3.6.10 with Hibernate Search 3.4.2.Final.
Imagine the illustrative example where we have two classes:

Code:
@Entity
@Indexed
public class Employee
{
    private String bio;

    @Field(name = "bio")
    public String getBio(){
        return bio;
    }
}


Code:
@Entity
@Indexed
public class Car
{
    private String description;

    @Field(name = "description")
    public String getDescription(){
        return description;
    }
}


Suppose that the two above classes have many more fields that we search on.

Assume we have an Employee record with bio "Employee's short bio" and a Car record with description "Car's short description" in our persistent storage and I perform a search query on the keyword "short" on both the Employee and the Car index.

I want to present the search results to the user in the form:

Employee matched with bio: "Employee's short bio"
Car matched with description: "Car's short description"

For this I need to know the names of the fields that matched, i.e. bio and decription in this case.
Is there any smart way of getting this information?
Certainly, it's possible to just manually check all fields, but I would prefer a nicer solution if there is one. Also, I've heard it's possible to do it through the Explanation object from Lucene, but this is apparently computationally expensive and therefore not feasible in my application.

Any help will be much appreciated.

Thanks,
goch


Top
 Profile  
 
 Post subject: Re: How to know which fields matched
PostPosted: Tue Aug 13, 2013 6:36 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Interesting problem.
You could try the Explanation approach: it might be computationally intensive, but it's only created for the matching entries. Since you mention you plan to expose these to the user, I assume the amount will be very reasonable as you can't fit millions of results on a single screen ;)

Consider that it would be quite common for the top results to match on multiple fields at the same time: multiple matches get scored higher than those which only match on a single field (*all depending on your Boost).

A rather advanced option is to open a raw IndexReader (http://docs.jboss.org/hibernate/search/4.3/reference/en-US/html_single/#IndexReaders), run the Lucene Query yourself using the Lucene API, and then you can iterate on the tokens on each matching Document. If you tokenize the user input (the keywords) using the same Analyzer that you're using for indexing you can verify which fields are matching.

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