<html><body 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></body></html>