O'Reilly logo

Instant Lucene.NET by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Searching for an index with TermQuery (Must know)

Now that an index is created, it can be used to execute queries. This recipe demonstrates what is probably the most basic of queries in Lucene.NET: the TermQuery. A TermQuery searches against document fields that are terms (in the previous example, the filename and length fields), where terms can be thought of as atomic search units and can have their explicit values compared to the search criteria.

How to do it...

The fluent API facade provides a method for performing a search on an index (aptly named search). The method takes a subclass of the Query class as a parameter that specifies what you want Lucene.NET to search for in the index.

The following example will execute a TermQuery for documents ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required