Dofs
Dofs

Reputation: 19197

NumericRangeQuery in NHibernate.Search

I am creating a search, where the user can both choose an interval and search on a term in the same go.

This is however giving me trouble, since I have up until have only used the usual text query.

I am wondering how I am to go about using both a NumericRangeQuery and a regular term query. Usually I would use a query below:

var parser = new MultiFieldQueryParser(
         new[] { "FromPrice", "ToPrice", "Description"}, new SimpleAnalyzer());
        Query query = parser.Parse(searchQuery.ToString());
        IFullTextSession session = Search.CreateFullTextSession(this.Session);
        IQuery fullTextQuery = session.CreateFullTextQuery(query, new[] { typeof(MyObject) });
        IList<MyObject> results = fullTextQuery.List<MyObject>();

But if I was to e.g. search the range FromPrice <-> ToPrice and also the description, how should I do this, since session.CreateFullTextQuery only takes one Query object?

Upvotes: 0

Views: 276

Answers (1)

Jf Beaulac
Jf Beaulac

Reputation: 5246

you can create a single query that is a BooleanQuery combining all the conditions you want to be met.

For the ranges, heres a link to the synthax using the QueryParser: http://lucene.apache.org/core/old_versioned_docs/versions/2_9_2/queryparsersyntax.html#Range Searches

Upvotes: 0

Related Questions