-->
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.  [ 8 posts ] 
Author Message
 Post subject: Conditionally Excluding Fields From The Index
PostPosted: Thu Jul 08, 2010 6:13 am 
Newbie

Joined: Thu Jul 08, 2010 5:45 am
Posts: 4
Hi folks,

We're looking into converting our search system to use Hibernate Search 3.1.1 (we're using Seam 2) and I'm trying to find out if there's a way to exclude class members from being indexed depending on the value of other members of the class. For example, I have an @Indexed class that looks a bit like this:

Code:
@Indexed
public class Foo {
    ...
    @IndexedEmbedded
    Bar bar;
    ...
    private boolean barExposed;
    ...
}

If the user wants others to be able to search for and view the data in bar, barExposed will be true. However, if it is false, we don't want bar to be indexed.

Is this possible? How could it be done?


Top
 Profile  
 
 Post subject: Re: Conditionally Excluding Fields From The Index
PostPosted: Fri Jul 09, 2010 3:06 am 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Correct me if I'm wrong but you always want to index the data right? It's only when it comes to searching you want to exclude the field from the search? There are a few ways to exclude the field from the search, however can I confirm that you are actually talking about excluding the fields from the search rather than excluding it from the indexing process altogether. For me it does not make sense to exclude it from the indexing but I don't know what your use case is.

Thanks


Top
 Profile  
 
 Post subject: Re: Conditionally Excluding Fields From The Index
PostPosted: Fri Jul 09, 2010 6:47 am 
Newbie

Joined: Thu Jul 08, 2010 5:45 am
Posts: 4
Hi amin-mc, thanks for your response.

The idea is to make sure the "hidden" data isn't searchable, e.g. if one entity's child's name is "foo" and childNameExposed is false then we wouldn't want searches for "foo" to return anything because that would leak data. Theoretically a sure-fire way to do this is to make sure the child entity doesn't even get indexed but if there's a more elegant way to do this (which doesn't complicate pagination, etc.) at search time then I welcome suggestions.

Apologies if my question doesn't make much sense, I'm still learning my way around HS.


Top
 Profile  
 
 Post subject: Re: Conditionally Excluding Fields From The Index
PostPosted: Fri Jul 09, 2010 8:00 am 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Hi

In the project that I worked on, we used filters to determine whether someone could see the result or not. Our requirement was if you were an insurance broker of a particular division then you could only see particular types of insurance risks. For this we indexed all the data and filtered them out based on the user role or some attribute. I wonder if this is more of what you need. I dont think it makes sense to exclude it from the indexing process. For example in the situation when you want to show the result, you won't be able show it unless you reindex the object this time with the value set to true.

I would recommend looking at filters and I'd be happy to walk you through the process.

Thanks
Amin


Top
 Profile  
 
 Post subject: Re: Conditionally Excluding Fields From The Index
PostPosted: Fri Jul 09, 2010 8:15 am 
Newbie

Joined: Thu Jul 08, 2010 5:45 am
Posts: 4
Hi,

I don't think our use cases are hugely similar: in my case, if a field is hidden, we never want it to be 'hit' by a search because the user has decided to hide that part of their profile. When the user decides not to hide the field, the exposed value is set to true and the entity is reindexed.

However, I would like to know more about your filtering process to see if the idea could be adapted.

Thanks


Top
 Profile  
 
 Post subject: Re: Conditionally Excluding Fields From The Index
PostPosted: Fri Jul 09, 2010 10:40 am 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
ok. Have a look at this:

http://docs.jboss.org/hibernate/search/ ... ing-bridge

especially class bridge. Let me know what you think.


Top
 Profile  
 
 Post subject: Re: Conditionally Excluding Fields From The Index
PostPosted: Sat Jul 10, 2010 4:01 pm 
Pro
Pro

Joined: Wed Oct 03, 2007 2:31 pm
Posts: 205
Hi
I've knocked a small example for you to show how the classbridge might work for your usecase. The following shows the bridge class

Code:
public class ExposeDateOfBirthClassBridge implements FieldBridge {

    public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
        Author user = (Author)value;
        if (user.isExposeDateOfBirth()) {
            Field dateOfBirth = new Field("authors.dateOfBirth", DateTools.dateToString(user.getDateOfBirth(), DateTools.Resolution.DAY), Field.Store.YES, Field.Index.NOT_ANALYZED);
            document.add(dateOfBirth);
        }
    }
}


And it is applied on the author class like this:

Code:
@Entity
@Table(name = "AUTHOR")
@ClassBridge( impl = ExposeDateOfBirthClassBridge.class)
public class Author implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ID")
    private Long id;

    @Field(index = Index.TOKENIZED, store = Store.NO)
    @Column(name = "F_NAME")
    private String firstName;

    @Field(index = Index.TOKENIZED, store = Store.NO)
    @Column(name = "M_NAME")
    private String middleName;

    @Field(index = Index.TOKENIZED, store = Store.NO)
    @Column(name = "L_NAME")
    private String lastName;

    @Column(name = "DOB")
    private Date dateOfBirth;

    @ManyToMany(
            cascade = {CascadeType.PERSIST, CascadeType.MERGE},
            mappedBy = "authors"
    )
    @ContainedIn
    private List<Book> publications;

    @Column(name = "EXPOSE_DOB")
    private boolean exposeDateOfBirth = false;


If you set the exposeDateOfBirth to true then it is indexed whereas false doesn't. I've tested this and verified it works. The thing to note is that I haven't added @Field to the dateOfBirth field, as it looks as though this field is indexed despite the classbridge. Anyway this should give you an idea. Let me know if this works for you.

Thanks


Top
 Profile  
 
 Post subject: Re: Conditionally Excluding Fields From The Index
PostPosted: Tue Jul 13, 2010 5:50 am 
Newbie

Joined: Thu Jul 08, 2010 5:45 am
Posts: 4
Hi Amin,

The @ClassBridge looks like it will work for us.

Thanks for all your help!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.