Java query builder API

Although you can construct a query using string manipulation, you might prefer an object-oriented approach. The Java™ query builder API provides an object-oriented form of each query operation.

The query builder API is provided in the package madison.mpi.search.query. To use the classes in this package, instantiate the ones that you need and then convert the query to string form by calling the toString() method.

See the Javadoc API documentation for full details about these classes.

TermQuery

Use the TermQuery for single-term searches. You can specify a single term or wildcard with the constructor.

new TermQuery("fred") ==> fred 
new TermQuery("str*") ==> str*

FieldQuery

Use FieldQuery to restrict a query to a single field.

new FieldQuery("name", new TermQuery("fred")) ==> name:fred 
new FieldQuery("address", new TermQuery("main")) ==> address:main 

AnyQuery

Use AnyQuery to combine results from multiple subqueries.

new AnyQuery()
    .addArg( new FieldQuery("name", new TermQuery("fred"))
    .addArg( new FieldQuery("name", new TermQuery("james")))
 ==> #any ( name:fred name:james )

AllQuery

Use AllQuery to combine results from multiple subqueries and you want only members that are displayed in all subqueries.

new AllQuery()
    .addArg( new FieldQuery("name", new TermQuery("fred"))
    .addArg( new FieldQuery("city", new TermQuery("chicago")))
 ==> #all ( name:fred city:chicago )

NoneQuery

Use NoneQuery to exclude results from subqueries.

new AllQuery()
    .addArg( new FieldQuery("name", new TermQuery("fred"))
    .addArg( new NoneQuery(
        new FieldQuery("city", new TermQuery("chicago"))))
 ==> #all( name:fred #none( city:chicago) )

PhoneticQuery

Use PhoneticQuery to query by using phonetically encoded terms. You must configure the index for phonetics to get any results from a phonetic query.

new PhoneticQuery( new FieldQuery("name", new TermQuery("mary"))) ==> #phonetic ( name:mary )

SynonymQuery

Use a SynonymQuery to query by using configured synonyms. You must configure the index for synonyms for a synonym query to work.

new SynonymQuery("nickname", new FieldQuery("name", new TermQuery("mary")))
 ==> #synonym nickname ( name:mary )

IntegerRangeQuery

Use an IntegerRangeQuery to search a range of INTEGER field values.

new IntegerRangeQuery("amount", 1, 100)
 ==> #range amount 1 100

FloatRangeQuery

Use a FloatRangeQuery to search a range of FLOAT field values.

new FloatRangeQuery("price", 2.99, 3.99)
 ==> #range price 2.99 3.99

DateRangeQuery

Use a DateRangeQuery to search a range of DATE field values.

new DateRangeQuery("dob", "1/1/1980", "12/31/1989")
 ==> #range dob 1/1/1980 12/31/1989