lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lukáš Vlček <lukas.vl...@gmail.com>
Subject Re: Querying across object relationships
Date Thu, 30 Jul 2009 22:15:19 GMT
Hi,

Lucene Document is a set of fields. Each field has a name and a textual
value. There is no notion of nested fields (filed inside a filed). Do not
focus too much on the XML representation of the index obtained from Luke.
Read Lucene documentation instead.
When indexing a java bean then what in fact has to happen is that you have
to transform tree-like data structure to a linear form: to one vector
(document) of vectors (fields). And this means that you have to lose some
information. In this case you are loosing mandatory - courseName relation.
Thus you have to keep this relation in arbitrary field in index - as long as
you want to have just ONE student Bob in your index. One option here is what
I have described before - adding a new fields into Student. These fileds
will somehow keep the mandatory - courseName relation.

If you can have many Bobs in the index then the Student class can not be a
searchable root and you have to change you Compass mappings.

Regards,
Lukas

http://blog.lukas-vlcek.com/


On Thu, Jul 30, 2009 at 11:36 PM, Paolo DiCanio <domurtag@yahoo.co.uk>wrote:

>
> Thanks Steven,
>
> I guess the index structure that I need in order to perform my query is:
>
> <doc id='1'>
>    <field name='courseName'>
>        <val>cooking</val>
>         <field name='mandatory'>
>            <val>N</val>
>         </field>
>    </field>
>    <field name='courseName'>
>        <val>art</val>
>        <field name='mandatory'>
>             <val>Y</val>
>        </field>
>    <field name='name'>
>        <val>Bob</val>
>    </field>
> </doc>
>
> But I'm not sure how to map my domain classes in order to achieve this (or
> even if it's possible)
>
>
> Steven A Rowe wrote:
> >
> > Hi Donal,
> >
> > I looked at the XML index dump you provided, and I can see that there is
> > only one document in the index.  This document matches your query.  I've
> > pasted it below, without the "$/*"-named fields I'm assuming Compass adds
> > to manage Lucene document -> Grails object mapping, and with just the
> > "name" attribute on the field elements:
> >
> >   <doc id='1'>
> >     <field name='courseName'>
> >       <val>cooking</val>
> >       <val>art</val>
> >     </field>
> >     <field name='mandatory'>
> >       <val>N</val>
> >       <val>Y</val>
> >     </field>
> >     <field name='name'>
> >      <val>Bob</val>
> >     </field>
> >   </doc>
> >
> > Compass's Lucene document to Grails object mapping is your problem here.
> >
> > In Lucene-land, the query (+courseName:cooking +mandatory:Y) matches the
> > above document, because the document contains those values in those
> > fields.
> >
> > So with that query, based on the Lucene document structure, you seem to
> be
> > asking the question: "Which student attends a cooking course and also
> > attends a mandatory course?".  Bob is a match.
> >
> > Steve
> >
> >> -----Original Message-----
> >> From: Donal Murtagh [mailto:domurtag@yahoo.co.uk]
> >> Sent: Thursday, July 30, 2009 3:10 PM
> >> To: java-user@lucene.apache.org
> >> Subject: Re: Querying across object relationships
> >>
> >> Basically the classes I'm indexing have the following relationships:
> >>
> >> Student 1------* Attendance 1------* Course
> >>
> >> The
> >> only root class is Student, i.e. only instances of this class can be
> >> returned from a search. I have a Student object graph that could be
> >> represented in JSON as follows:
> >>
> >> {
> >>   name: Bob,
> >>   attendances: [
> >>     {mandatory: N, course: {name: cooking}},
> >>     {mandatory: Y, course: {name: art}}]
> >> }
> >>
> >> When I search for an instance of Student using the query:
> >>
> >>   "+courseName:cooking +mandatory:Y"
> >>
> >> Bob
> >> is returned because, because he attends a course named "cooking" and he
> >> attends a mandatory course (named "art).. But what I really want to
> >> search for is students that attend a mandatory cooking course. It
> >> doesn't appear to be possible to do this based on the responses
> >> provided here:
> >> http://stackoverflow.com/questions/1202422/lucene-query-
> >> syntax/1203186#1203186
> >>
> >> I
> >> opened the Student index in Luke, exported it to XML and have appended
> >> the results here:
> >> http://pastebin.com/m6e5bbcf3
> >>
> >> I don't really know how to interpret this
> >> myself, but thanks in advance for any further help you can provide.
> >>
> >> - Don
> >>
> >>
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Querying-across-object-relationships-tp24727196p24747745.html
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message