<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Very elegant. &nbsp;I'm generally a big fan of 'builder' patterns like this, but this really isn't a DSL, is it? &nbsp;:) &nbsp;When you first mentioned a DSL I had visions of defining a new grammar and an ANTLR parser, etc. &nbsp;But that is overkill.<div><br></div><div>This approach certainly works, and will almost certainly perform better too. &nbsp;One question: for the sake of brevity, why SealedQueryBuilder instead of QueryBuilder ? &nbsp;:)</div><div><br></div><div>Also, I still think that if this is a generic helper factory that helps you build Lucene queries - and has no knowledge of how and where the query is used (why should it?) - then this should be something people can use outside of HS or Infinispan. &nbsp;E.g., directly with Lucene. &nbsp;</div><div><br></div><div><br><div><div>On 26 Aug 2009, at 12:39, Emmanuel Bernard wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>I've been thinking about a DSL to build Lucene queries in the last day.</div><div>What do you think of this proposal?</div><div><br></div><div>A few remarks:</div><div>&nbsp;- it asks the analyzer so that we correctly apply the analyzer on terms</div><div>&nbsp;- it has a few query factory methods</div><div>&nbsp;- it contains a few orthogonal operations</div><div>&nbsp;- I am not quite satisfied with how boolean is handled, any idea?</div><div><br></div><div><br></div><div><br></div><div><b> <span class="Apple-style-span" style="font-family: Arial; font-weight: normal; "><div><b><div>Examples</div><div><br><br></div><div><span class="Apple-style-span" style="font-weight: normal;"><div>SealedQueryBuilder qb = searchFactory.withEntityAnalyzer(Address.class);</div><div><br><br></div><div>Query luceneQuery =&nbsp;</div><div>qb.must(Occurs.MUST)</div><div>&nbsp;&nbsp;&nbsp; .add(</div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; qb.boolean(Occurs.Should)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.add( qb.term("city", "Atlanta").boostedTo(4).createQuery() )</div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .add( qb.term("address1", "Peachtree").fuzzy().createQuery() )</div><div>&nbsp;&nbsp;&nbsp; )</div><div>&nbsp;&nbsp;&nbsp; .add(</div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; qb.from("movingDate", "200604").to("201201").exclusive().createQuery()</div><div>&nbsp;&nbsp; &nbsp;)</div><div>&nbsp;&nbsp; &nbsp;.createQuery();</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div></span></div></b></div><div><b><br><br></b></div><div><b>Analyzer choice</b></div><div>queryBuilder.withAnalyzer(Analyzer)</div><div>queryBuilder.withEntityAnalyzer(Class&lt;?&gt;)</div><div>queryBuilder.basedOnEntityAnalyzer(Class&lt;?&gt;)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.overridesForField(String field, Analyzer)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.overridesForField(String field, Analyzer)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;.build() //sucky name</div><div>returns a SealedQueryBuilder //sucky name</div><div><br><br></div><div>SealedQueryBuilder contains the factory methods</div><div><br><br></div><div><b><br><br></b></div><div><b>Factory methods</b></div><div>Hosted onSealedQueryBuilder</div><div><br><br></div><div>.term(String field, String text) //define a new query</div><div>.term(String field, String text) //define a new query</div><div>&nbsp;&nbsp; .ignoreAnalyzer() //ignore the analyzer, optional</div><div>&nbsp;&nbsp;&nbsp;.fuzzy()&nbsp;//API prevent wildcard calls, optional</div><div>&nbsp;&nbsp; &nbsp; .threshold()&nbsp;//optional</div><div>&nbsp;&nbsp; &nbsp; .prefixLengh() //optional</div><div>.term(String field, String value)</div><div>&nbsp;&nbsp; .wildcard()&nbsp;//API prevent fuzzy calls, optional</div><div><br><br></div><div>//range query</div><div>.from(String field, String text)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; .exclusive() //optional</div><div>&nbsp;&nbsp; &nbsp;.to(String text)</div><div>&nbsp;&nbsp; &nbsp; &nbsp; .exclusive() //optional</div><div>&nbsp;&nbsp; &nbsp;.constantScore() //optional, due to constantScoreRangeQuery but in practice inherited from the common operations</div><div><br><br></div><div>//match all docs</div><div>.all()&nbsp;</div><div><br><br></div><div>//phrase query</div><div>.phrase(String field)</div><div>&nbsp;&nbsp; &nbsp;.ignoreAnalyzer() //ignore the analyzer, optional</div><div>&nbsp;&nbsp; &nbsp;.addWord(String text) //at least one</div><div>&nbsp;&nbsp; &nbsp;.addWord(String text)</div><div>&nbsp;&nbsp; &nbsp;.sentence(String text) //do we need that?</div><div>&nbsp;&nbsp; &nbsp;.slop() //optional</div><div><br><br></div><div>//search multiple fields for same value</div><div>.searchInMultipleFields()</div><div>&nbsp;&nbsp;.onField(String field)</div><div>&nbsp;&nbsp; &nbsp; &nbsp;.boostedTo(float) //optional</div><div>&nbsp;&nbsp; &nbsp; &nbsp;.ignoreAnalyzer()&nbsp;//optional</div><div>&nbsp;&nbsp;.onField(String field)</div><div>&nbsp;&nbsp;.forWords(String) //do we need that?</div><div>&nbsp;&nbsp;.forWord(String)</div><div><br><br></div><div><br><br></div><div><b>Boolean operations</b></div><div><div>SealedQueryBuilder contains the boolean methods</div></div><div><div><div><div><br><br></div><div>.boolean(Occurs occurs)<br><br></div><div>&nbsp;&nbsp;.add( qb.from().to() )</div><div>&nbsp;&nbsp;.add( ... )</div><div><br><br></div></div></div></div><div><br><br></div><div><b>Works on all queries</b></div><div>&nbsp;&nbsp; &nbsp;.boostedTo()</div><div>&nbsp;&nbsp; &nbsp;.constantScore()&nbsp;</div><div>&nbsp;&nbsp; &nbsp;.filter(Filter) //filter the current query</div><div>&nbsp;&nbsp; &nbsp;.scoreMultipliedByField(field) //FieldScoreQuery + FunctionQuery?? //Not backed</div><div>&nbsp;&nbsp; &nbsp;.createQuery()</div><div><br><br></div><div><br><br></div><div><b>Todo</b></div><div>Span*Queries</div><div>&nbsp;&nbsp;</div><div>MultiPhraseQuery - needs to fillup all accepted terms</div><div>FieldScoreQuery</div><div>ValueSourceQuery</div><div>FuzzyLikeThis</div><div>MoreLikeThis</div></span></b></div><div><div><br></div></div><br><div><div>On 25 août 09, at 16:43, Manik Surtani wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><br>On 25 Aug 2009, at 13:34, Emmanuel Bernard wrote:<br><br><blockquote type="cite"><br></blockquote><blockquote type="cite">On 25 août 09, at 14:27, Manik Surtani wrote:<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><blockquote type="cite">A DSL would work, but I'd rather not define our own language here.<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">Which is why I asked for a standard. &nbsp;Perhaps something based on SQL/<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">JPA-QL? &nbsp;Or are you thinking &nbsp;DSL specific to Lucene - which could<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">be used by any/all of {Lucene, Hibernate Search, Infinispan}? &nbsp;In<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">which case the DSL should ideally be a Lucene project.<br></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Yes I was thinking about a DSL used for Hibernate Search and maybe all<br></blockquote><blockquote type="cite">of Lucene if the HS integration benefits offer no value towards<br></blockquote><blockquote type="cite">simplicity (but I think i can offer value).<br></blockquote><br><br>Ok, this should be interesting. &nbsp;Lets chat about this some more - have &nbsp;<br>you drafted any thoughts around this DSL somewhere?<br></div></blockquote></div><br><div><br></div><div><br></div></div>_______________________________________________<br>infinispan-dev mailing list<br><a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>https://lists.jboss.org/mailman/listinfo/infinispan-dev</blockquote></div><br><div apple-content-edited="true"> <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>--</div><div>Manik Surtani</div><div><a href="mailto:manik@jboss.org">manik@jboss.org</a></div><div>Lead, Infinispan</div><div>Lead, JBoss Cache</div><div><a href="http://www.infinispan.org">http://www.infinispan.org</a></div><div><a href="http://www.jbosscache.org">http://www.jbosscache.org</a></div><div><br></div></div></span><br class="Apple-interchange-newline"></div></span><br class="Apple-interchange-newline"> </div><br></div></body></html>