Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7767723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:44:49+00:00 2026-06-01T15:44:49+00:00

I am using Advanced.LuceneQuery e.g. RavenQueryStatistics stats = null; vm.Products = DocumentSession.Advanced.LuceneQuery<Product>(Products/Index) .Statistics(out stats)

  • 0

I am using Advanced.LuceneQuery e.g.

RavenQueryStatistics stats = null;
vm.Products = DocumentSession.Advanced.LuceneQuery<Product>("Products/Index")
            .Statistics(out stats)
            .Where(searchExpression)
            .OrderBy(columnToSortBy)
            .Skip((vm.PageIndex - 1) * vm.PageSize)
            .Take(vm.PageSize)
            .ToArray()
            ;

with this index

public Products_Index()
{
    Map = products => from p in products
                      select new
                      {
                          p.ItemNum,
                          p.BrandName,
                          p.ProductName,
                          p.Catalog,
                          p.UOM,
                          p.CasePack,
                          p.AveWeight,
                          p.CatalogId,
                          p.HasPicture,
                          p.INFO2,
                          p.IsOfflineSupplierItem,
                          p.IsRebateItem,
                          p.IsSpecialOrderItem,
                          p.IsSpecialPriceItem,
                          p.Price
                      };

    Indexes.Add(x => x.INFO2, FieldIndexing.Analyzed);
    Indexes.Add(x => x.CatalogId, FieldIndexing.Analyzed);
    Indexes.Add(x => x.HasPicture, FieldIndexing.Analyzed);
    Indexes.Add(x => x.IsOfflineSupplierItem, FieldIndexing.Analyzed);
    Indexes.Add(x => x.IsRebateItem, FieldIndexing.Analyzed);
    Indexes.Add(x => x.IsSpecialOrderItem, FieldIndexing.Analyzed);
    Indexes.Add(x => x.IsSpecialPriceItem, FieldIndexing.Analyzed);
    Indexes.Add(x => x.Price, FieldIndexing.Analyzed);
}

and a typical expression to execute would look like this

"INFO2:(blue*) AND INFO2:(pen*) AND HasPicture:(True) AND IsSpecialOrderItem:(True) AND IsRebateItem:(True) AND IsOfflineSupplierItem:(True) AND CatalogId:(736275001)" 

Now I need to incorporate a range search based on the price column/index. What would the syntax be to construct that portion of my where clause?

The requirements are

Price >= FromNumber
Price <= ToNumber

EDIT: The method that constructs the where clause

private void ProductSearch(ProductSearchViewModel vm)
{

    var terms = vm.SearchTerm
        .ToLower()
        .Split(new char[] { ' ' });

    // Start buildeing up the query
    var sb = new StringBuilder();

    // terms
    foreach (string term in terms)
    {
        sb.AppendFormat("INFO2:({0}*) AND ", term);
    }

    if (vm.Filters != null)
    {

        // picture 
        if (vm.Filters.IsAtrFilterPictureSelected)
        {
            sb.AppendFormat("HasPicture:({0}) AND ", vm.Filters.IsAtrFilterPictureSelected);
        }
        // special order
        if (vm.Filters.IsAtrFilterSpecialOrderSelected)
        {
            sb.AppendFormat("IsSpecialOrderItem:({0}) AND ", vm.Filters.IsAtrFilterSpecialOrderSelected);
        }
        // special price
        if (vm.Filters.IsAtrFilterSpecialPriceSelected)
        {
            sb.AppendFormat("IsSpecialPriceItem:({0}) AND ", vm.Filters.IsAtrFilterSpecialPriceSelected);
        }
        // rebate
        if (vm.Filters.IsAtrFilterRebateSelected)
        {
            sb.AppendFormat("IsRebateItem:({0}) AND ", vm.Filters.IsAtrFilterRebateSelected);
        }
        // offline supplier
        if (vm.Filters.IsAtrFilterOfflineItemSelected)
        {
            sb.AppendFormat("IsOfflineSupplierItem:({0}) AND ", vm.Filters.IsAtrFilterOfflineItemSelected);
        }
        // catalog
        if (vm.Filters.CatalogSelected > 0)
        {
            sb.AppendFormat("CatalogId:({0}) AND ", vm.Filters.CatalogSelected);
        }
        // price range
        if (vm.Filters.PriceFrom > 0 && vm.Filters.PriceTo > 0)
        {
            sb.AppendFormat("Price_Range:[{0} TO {1}]", NumberUtil.NumberToString((double)vm.Filters.PriceFrom), NumberUtil.NumberToString((double)vm.Filters.PriceTo));
        }

    }

    // remove the last 'AND' from the string 
    var searchExpression = sb.ToString();
    if (searchExpression.EndsWith("AND "))
    {
        searchExpression = searchExpression.Substring(0, searchExpression.LastIndexOf("AND "));
    }

    // trace it out
    Logger.WriteMessage(Infrastructure.Logging.LogLevel.Info, "Search Term: " + searchExpression);

    Stopwatch watch = Stopwatch.StartNew();

    string columnToSortBy = string.Empty;
    if (vm.GridParams != null)
    {
        // Luncene specific way of ordering
        columnToSortBy = vm.GridParams.sidx ?? "Price";
        columnToSortBy = vm.GridParams.sord == "asc" ? "+" + columnToSortBy : "-" + columnToSortBy;
    }

    // execution of query
    RavenQueryStatistics stats = null;
    vm.Products = DocumentSession.Advanced.LuceneQuery<Product>("Products/Index")
                .Statistics(out stats)
                .Where(searchExpression)
                .OrderBy(columnToSortBy)
                .Skip((vm.PageIndex - 1) * vm.PageSize)
                .Take(vm.PageSize)
                .ToArray()
                ;

    watch.Stop();
    vm.TotalResults = stats.TotalResults;
    Logger.WriteMessage(Infrastructure.Logging.LogLevel.Info, "Search Time: " + watch.ElapsedMilliseconds);

}

Thank you,
Stephen

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:44:50+00:00Added an answer on June 1, 2026 at 3:44 pm

    You need something like this (note the “_Range”):

    Price_Range:[FromNumber TO ToNumber]
    

    See the Lucene query syntax docs for the full info. Also you need to put the number in the correct Hex format. Make sure you use the built-in functions in the NumberUtils class in the Raven.Abstractions namespace to do this for you, rather than doing it yourself.

    BUT is there a reason you’re using the low-level Lucene API and building the queries by hand? There’s a strongly typed API with LINQ support that will do a lot of the work for you (session.Query<T>()).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been using http://www.regexplanet.com/advanced/java/index.html to test a regular expression I've written. The regular expression
I am using Advanced DataGrid of Flex 3 with hierarchical data. The itemRenderer is
Is it possible to initialise an array in Java using the 'advanced' for loop?
Qt library includes advanced meta-programming capabilities using they own preprocessing moc compiler. Does anyone
I'm using the following form as part of an Advanced Search page on my
I'm using Oracle Advanced Queues via JMS from within Websphere App Server. Does anyone
When using Advanced Database Crawler for searching in Sitecore is it possible to combine
The browser on the iPhone is capable of using advanced web technologies introduced in
I am trying to schedule con style job using advanced python scheduler. Everything is
I have an SSRS report with a simple tablix control where (using advanced mode

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.