Using Lucene.Net Query Objects

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);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s