You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Pravin Thokal <pr...@systoolsgroup.com> on 2016/06/13 06:14:37 UTC

How to use Query Time Join with Lucene 5.3.0?

I am referring this
<http://blog.trifork.com/2012/01/22/query-time-joining-in-lucene/>link for
usage of query time join and I am able to use following method

   createJoinQuery(String fromField, boolean multipleValuesPerDocument,
String toField, Query fromQuery, IndexSearcher fromSearcher, ScoreMode
scoreMode)

Parameters:
fromField - The from field to join from
multipleValuesPerDocument - Whether the from field has multiple terms per
document
toField - The to field to join to
fromQuery - The query to match documents on the from side
fromSearcher - The searcher that executed the specified fromQuery
scoreMode - Instructs how scores from the fromQuery are mapped to the
returned query
However I would like to use following createJoinQuery() with different
parameters

public static Query createJoinQuery(String joinField,Query fromQuery,
                Query toQuery,IndexSearcher searcher,ScoreMode scoreMode,
                MultiDocValues.OrdinalMap ordinalMap) throws IOException

joinField - The SortedDocValues field containing the join values
fromQuery - The query containing the actual user query. Also the fromQuery
can only match "from" documents.
toQuery - The query identifying all documents on the "to" side.
searcher - The index searcher used to execute the from query
scoreMode - Instructs how scores from the fromQuery are mapped to the
returned query
ordinalMap - The ordinal map constructed over the joinField. In case of a
single segment index, no ordinal map needs to be provided.
For this methods, I am referring this
<https://lucene.apache.org/core/5_3_0/join/org/apache/lucene/search/join/JoinUtil.html>link.
I don't have any clue for the parameter ordinalMap and how to create it. It
will be great help if any one explains it with example.

Best Regards,

*Pravin Thokal*

*Senior Product Engineer,*

*SysTools Software Pvt. Ltd.*

202, Pentagon P3, Magarpatta CyberCity, Pune - 411028 , Maharashtra, India.

+91-02-60505558 | www.systoolsgroup.com | www.mailxaminer.com

Fwd: How to use Query Time Join with Lucene 5.3.0?

Posted by Pravin Thokal <pr...@systoolsgroup.com>.
Hello,


I am referring this
<http://blog.trifork.com/2012/01/22/query-time-joining-in-lucene/>link for
usage of query time join and I am able to use following method

   createJoinQuery(String fromField, boolean multipleValuesPerDocument,
String toField, Query fromQuery, IndexSearcher fromSearcher, ScoreMode
scoreMode)

Parameters:
fromField - The from field to join from
multipleValuesPerDocument - Whether the from field has multiple terms per
document
toField - The to field to join to
fromQuery - The query to match documents on the from side
fromSearcher - The searcher that executed the specified fromQuery
scoreMode - Instructs how scores from the fromQuery are mapped to the
returned query
However I would like to use following createJoinQuery() with different
parameters

public static Query createJoinQuery(String joinField,Query fromQuery,
                Query toQuery,IndexSearcher searcher,ScoreMode scoreMode,
                MultiDocValues.OrdinalMap ordinalMap) throws IOException

joinField - The SortedDocValues field containing the join values
fromQuery - The query containing the actual user query. Also the fromQuery
can only match "from" documents.
toQuery - The query identifying all documents on the "to" side.
searcher - The index searcher used to execute the from query
scoreMode - Instructs how scores from the fromQuery are mapped to the
returned query
ordinalMap - The ordinal map constructed over the joinField. In case of a
single segment index, no ordinal map needs to be provided.
For this methods, I am referring this
<https://lucene.apache.org/core/5_3_0/join/org/apache/lucene/search/join/JoinUtil.html>link.
I don't have any clue for the parameter ordinalMap and how to create it. It
will be great help if any one explains it with example.

Best Regards,

*Pravin Thokal*

*Senior Product Engineer,*

*SysTools Software Pvt. Ltd.*

202, Pentagon P3, Magarpatta CyberCity, Pune - 411028 , Maharashtra, India.

+91-02-60505558 | www.systoolsgroup.com | www.mailxaminer.com

Re: How to use Query Time Join with Lucene 5.3.0?

Posted by Martijn v Groningen <ma...@gmail.com>.
The blog you're referring to is explaining the query time join
implementation that isn't using ordinal map, which is the first method in
the JoinUtil class (with the ordinal map as parameter).

If you want to use the method that uses global ordinals you can use this
snippet to create an OrdinalMap instance:

IndexReader r = indexSearcher.getIndexReader();
SortedDocValues[] values = new SortedDocValues[r.leaves().size()];
for (int i = 0; i < values.length; i++) {
  LeafReader leafReader =  r.leaves().get(i).reader();
  values[i] = DocValues.getSorted(leafReader, joinField);
}
MultiDocValues.OrdinalMap ordinalMap = MultiDocValues.OrdinalMap.build(
  r.getCoreCacheKey(), values, PackedInts.DEFAULT
);

I copied this snippet from this test:
https://github.com/apache/lucene-solr/blob/e44509f2dfc22f95f0a13372461d6db58b66611c/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java#L273

If you use this join implementation it is important that you reuse the
OrdinalMap as it is expensive to create. Reuse the ordinal map as long as
you use the IndexReader, if (re)open an new IndexReader you should build a
new ordinal map.


On 13 June 2016 at 08:14, Pravin Thokal <pr...@systoolsgroup.com> wrote:

> I am referring this
> <http://blog.trifork.com/2012/01/22/query-time-joining-in-lucene/>link for
> usage of query time join and I am able to use following method
>
>    createJoinQuery(String fromField, boolean multipleValuesPerDocument,
> String toField, Query fromQuery, IndexSearcher fromSearcher, ScoreMode
> scoreMode)
>
> Parameters:
> fromField - The from field to join from
> multipleValuesPerDocument - Whether the from field has multiple terms per
> document
> toField - The to field to join to
> fromQuery - The query to match documents on the from side
> fromSearcher - The searcher that executed the specified fromQuery
> scoreMode - Instructs how scores from the fromQuery are mapped to the
> returned query
> However I would like to use following createJoinQuery() with different
> parameters
>
> public static Query createJoinQuery(String joinField,Query fromQuery,
>                 Query toQuery,IndexSearcher searcher,ScoreMode scoreMode,
>                 MultiDocValues.OrdinalMap ordinalMap) throws IOException
>
> joinField - The SortedDocValues field containing the join values
> fromQuery - The query containing the actual user query. Also the fromQuery
> can only match "from" documents.
> toQuery - The query identifying all documents on the "to" side.
> searcher - The index searcher used to execute the from query
> scoreMode - Instructs how scores from the fromQuery are mapped to the
> returned query
> ordinalMap - The ordinal map constructed over the joinField. In case of a
> single segment index, no ordinal map needs to be provided.
> For this methods, I am referring this
> <
> https://lucene.apache.org/core/5_3_0/join/org/apache/lucene/search/join/JoinUtil.html
> >link.
> I don't have any clue for the parameter ordinalMap and how to create it. It
> will be great help if any one explains it with example.
>
> Best Regards,
>
> *Pravin Thokal*
>
> *Senior Product Engineer,*
>
> *SysTools Software Pvt. Ltd.*
>
> 202, Pentagon P3, Magarpatta CyberCity, Pune - 411028 , Maharashtra, India.
>
> +91-02-60505558 | www.systoolsgroup.com | www.mailxaminer.com
>



-- 
Met vriendelijke groet,

Martijn van Groningen