Skip to content

Lucinq using Lucene Query Objects

cardinal252 edited this page Sep 27, 2013 · 6 revisions

Lucinq has been developed with Lucene at its heart, as such, the QueryBuilder deals almost completely with Query objects that come straight from the API, its extension methods in fact generate query objects, its Build() method - also generates a query object that could be put straight back into the native lucene engine. This translates to an api that does not restrict you to its calls, if Lucinq doesn't have it and Lucene does - simply use Lucene :D.

LuceneSearch search = new LuceneSearch(GeneralConstants.Paths.BBCIndex);
// raw lucene object
TermQuery query = new TermQuery(new Term(BBCFields.Title, "africa"));
            
// executed directly by the search
LuceneSearchResult result = search.Execute(query);
Assert.AreEqual(8, result.TotalHits);

// or by through a querybuilder
IQueryBuilder queryBuilder = new QueryBuilder();
queryBuilder.Add(query, Matches.Always);
LuceneSearchResult result2 = search.Execute(queryBuilder);
Assert.AreEqual(8, result2.TotalHits);