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

  • Home
  • SEARCH
  • 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 7751727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:37:20+00:00 2026-06-01T11:37:20+00:00

This question builds on the following question (s) Indexing : How do I construct

  • 0

This question builds on the following question (s)

Indexing : How do I construct my RavenDb static indexes for this document, given these requirements?

Simple Where clause with paging : How to construct a proper WHERE clause with RavenDb

The essence of the question is how do I dynamically add or remove fields to participate in a where clause?

Document:

[Serializable]
public class Product
{
    public string AveWeight { get; set; }

    public string BrandName { get; set; }

    public string CasePack { get; set; }

    public string Catalog { get; set; }

    public decimal CatalogId { get; set; }

    public decimal CategoryId { get; set; }

    public string Info { get; set; }

    public bool IsOfflineSupplierItem { get; set; }

    public bool IsRebateItem { get; set; }

    public bool IsSpecialOrderItem { get; set; }

    public bool IsSpecialPriceItem { get; set; }

    public bool IsTieredPricingItem { get; set; }

    public string ItemNum { get; set; }

    public string ManufactureName { get; set; }

    public string ManufactureNum { get; set; }

    public decimal OffineSupplierId { get; set; }

    public string PackageRemarks { get; set; }

    public decimal Price { get; set; }

    public decimal PriceGroupId { get; set; }

    public decimal ProductId { get; set; }

    public string ProductName { get; set; }

    public int Quantity { get; set; }

    public string SupplierName { get; set; }

    public string UOM { get; set; }

    public string Upc { get; set; }

    public string Url { get; set; }

}

Index:

if (store.DatabaseCommands.GetIndex("Products_Index") == null)
{
    store.DatabaseCommands.PutIndex("Products_Index", new IndexDefinitionBuilder<Product>
    {
        Map = products => from p in products
                          select new { p.CatalogId, 
                                         p.HasPicture, 
                                         p.INFO2, 
                                         p.IsOfflineSupplierItem, 
                                         p.IsRebateItem, 
                                         p.IsSpecialOrderItem, 
                                         p.IsSpecialPriceItem, 
                                         p.IsTieredPricingItem, 
                                         p.Price },
        Indexes = 
        { 
            { x => x.INFO2, FieldIndexing.Analyzed }, 
            { x => x.CatalogId, FieldIndexing.Default},
            { x => x.HasPicture, FieldIndexing.Default},
            { x => x.IsOfflineSupplierItem, FieldIndexing.Default},
            { x => x.IsRebateItem, FieldIndexing.Default},
            { x => x.IsSpecialOrderItem, FieldIndexing.Default},
            { x => x.IsSpecialPriceItem, FieldIndexing.Default},
            { x => x.IsTieredPricingItem, FieldIndexing.Default},
            { x => x.Price, FieldIndexing.Default}
        }
    });
}

Naive Where clause

  string  t1 = "foo";
  bool    t2 = true;
  decimal t3 = 100m;

  products = DocumentSession.Query<Product>()
      .Statistics(out stats)
      .Where(p => p.INFO2.StartsWith(t1) && p.IsRebateItem == t2 && p.CatalogId = t3) 
      .OrderByField(columnToSortBy, columnToSortByAsc)
      .Skip(pageIndex * pageSize)
      .Take(pageSize)
      .ToList()
      ;

First Pass at Advanced Query

 var products = s.Advanced.LuceneQuery<Product>("Products")
    .WhereEquals("Catalog", "National Catalog")
    .ToList()
    ;

which throws an exception

A first chance exception of type ‘Lucene.Net.QueryParsers.QueryParser.LookaheadSuccess’ occurred in Lucene.Net.dll
A first chance exception of type ‘System.IO.IOException’ occurred in Lucene.Net.dll

Second pass (works)

 result = s.Advanced.LuceneQuery<Product>("Products_Index")
 .Where("CatalogId:(736275001) AND HasPicture:(true) AND IsOfflineSupplierItem:(false)")
 .ToArray();

Third Pass (and fastest yet)

result = s.Advanced.LuceneQuery<Product>("Products/Index")
    .Statistics(out stats)
    .WhereStartsWith("INFO2", "ink")
    .AndAlso()
    .WhereStartsWith("INFO2", "pen")
    .AndAlso()
    .WhereEquals("CatalogId", 736275001)
    .AndAlso()
    .WhereEquals("HasPicture", true)
    .AndAlso()
    .WhereEquals("IsOfflineSupplierItem", false)
    .AndAlso()
    .WhereEquals("IsRebateItem", false)
    .AndAlso()
    .WhereEquals("IsSpecialOrderItem", false)
    .AndAlso()
    .WhereEquals("IsSpecialPriceItem", false)
    .ToArray()
    ;
  • 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-01T11:37:21+00:00Added an answer on June 1, 2026 at 11:37 am

    If you want to do this dynamically, you can use the DocumentSession.Advanced.LuceneQuery, which allows you to pass strings as the property names for the index.
    That way, you don’t have to deal with the strongly typed issues.

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

Sidebar

Related Questions

Following on from this question , I'm using a simple ViewModel class to test
This question builds on the following question: How to get Elmah working with ASP.NET
This question builds off of a previously asked question: Pass by reference multidimensional array
This is an iOS question. I build a static library (a framework in iOS)
Following on from this question , I now want to know how to stop
following this question : Best approach for oldschool 2D zelda-like game Thank to previous
EDIT : This question duplicates How to access the current Subversion build number? (Thanks
This is a follow-up to this question. I am trying to build a mod_rewrite
I'm using the accepted answer to this question to help me build an HTML
This may seem like a dumb question, but can an app build with c#

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.