1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.forms.business.form;
35
36 import java.util.List;
37
38 import fr.paris.lutece.plugins.forms.business.form.filter.querypart.IFormFilterLuceneQueryPart;
39 import fr.paris.lutece.plugins.forms.business.form.filter.querypart.IFormFilterQueryPart;
40 import fr.paris.lutece.plugins.forms.business.form.panel.initializer.querypart.IFormPanelInitializerLuceneQueryPart;
41 import fr.paris.lutece.plugins.forms.business.form.panel.initializer.querypart.IFormPanelInitializerQueryPart;
42 import org.apache.lucene.search.BooleanClause;
43 import org.apache.lucene.search.BooleanQuery;
44 import org.apache.lucene.search.Query;
45
46
47
48
49 public final class LuceneQueryBuilder
50 {
51
52
53
54 private LuceneQueryBuilder( )
55 {
56
57 }
58
59
60
61
62
63
64
65
66
67
68 public static Query buildQuery( List<IFormPanelInitializerQueryPart> listFormPanelInitializerQueryPart, List<IFormFilterQueryPart> listFormFilterQueryPart )
69 {
70 BooleanQuery.Builder booleanQueryBuilder = new BooleanQuery.Builder( );
71 for ( IFormFilterQueryPart formFilterQueryPart : listFormFilterQueryPart )
72 {
73 if ( formFilterQueryPart instanceof IFormFilterLuceneQueryPart )
74 {
75 Query queryFormFilterQueryPart = ( (IFormFilterLuceneQueryPart) formFilterQueryPart ).getFormFilterQuery( );
76 if ( queryFormFilterQueryPart != null )
77 {
78 booleanQueryBuilder.add( queryFormFilterQueryPart, BooleanClause.Occur.FILTER );
79 }
80 }
81 }
82 for ( IFormPanelInitializerQueryPart formPanelInitializerQueryPart : listFormPanelInitializerQueryPart )
83 {
84 if ( formPanelInitializerQueryPart instanceof IFormPanelInitializerLuceneQueryPart )
85 {
86 Query queryFormFilterQueryPart = ( (IFormPanelInitializerLuceneQueryPart) formPanelInitializerQueryPart ).getFormPanelInitializerSelectQuery( );
87 if ( queryFormFilterQueryPart != null )
88 {
89 booleanQueryBuilder.add( queryFormFilterQueryPart, BooleanClause.Occur.FILTER );
90 }
91 }
92 }
93 return booleanQueryBuilder.build( );
94 }
95
96 }