<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Very elegant. I'm generally a big fan of 'builder' patterns like this, but this really isn't a DSL, is it? :) When you first mentioned a DSL I had visions of defining a new grammar and an ANTLR parser, etc. But that is overkill.<div><br></div><div>This approach certainly works, and will almost certainly perform better too. One question: for the sake of brevity, why SealedQueryBuilder instead of QueryBuilder ? :)</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. E.g., directly with Lucene. </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> - it asks the analyzer so that we correctly apply the analyzer on terms</div><div> - it has a few query factory methods</div><div> - it contains a few orthogonal operations</div><div> - 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 = </div><div>qb.must(Occurs.MUST)</div><div> .add(</div><div> qb.boolean(Occurs.Should)</div><div> .add( qb.term("city", "Atlanta").boostedTo(4).createQuery() )</div><div> .add( qb.term("address1", "Peachtree").fuzzy().createQuery() )</div><div> )</div><div> .add(</div><div> qb.from("movingDate", "200604").to("201201").exclusive().createQuery()</div><div> )</div><div> .createQuery();</div><div> </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<?>)</div><div>queryBuilder.basedOnEntityAnalyzer(Class<?>)</div><div> .overridesForField(String field, Analyzer)</div><div> .overridesForField(String field, Analyzer)</div><div> .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> .ignoreAnalyzer() //ignore the analyzer, optional</div><div> .fuzzy() //API prevent wildcard calls, optional</div><div> .threshold() //optional</div><div> .prefixLengh() //optional</div><div>.term(String field, String value)</div><div> .wildcard() //API prevent fuzzy calls, optional</div><div><br><br></div><div>//range query</div><div>.from(String field, String text)</div><div> .exclusive() //optional</div><div> .to(String text)</div><div> .exclusive() //optional</div><div> .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() </div><div><br><br></div><div>//phrase query</div><div>.phrase(String field)</div><div> .ignoreAnalyzer() //ignore the analyzer, optional</div><div> .addWord(String text) //at least one</div><div> .addWord(String text)</div><div> .sentence(String text) //do we need that?</div><div> .slop() //optional</div><div><br><br></div><div>//search multiple fields for same value</div><div>.searchInMultipleFields()</div><div> .onField(String field)</div><div> .boostedTo(float) //optional</div><div> .ignoreAnalyzer() //optional</div><div> .onField(String field)</div><div> .forWords(String) //do we need that?</div><div> .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> .add( qb.from().to() )</div><div> .add( ... )</div><div><br><br></div></div></div></div><div><br><br></div><div><b>Works on all queries</b></div><div> .boostedTo()</div><div> .constantScore() </div><div> .filter(Filter) //filter the current query</div><div> .scoreMultipliedByField(field) //FieldScoreQuery + FunctionQuery?? //Not backed</div><div> .createQuery()</div><div><br><br></div><div><br><br></div><div><b>Todo</b></div><div>Span*Queries</div><div> </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. Perhaps something based on SQL/<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite">JPA-QL? Or are you thinking 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}? 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. Lets chat about this some more - have <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>