Hagay Albo
Hagay Albo

Reputation: 21

facets with ravendb

i am trying to work with the facet ability in ravendb but getting strange results.

i have a documents like :

 {
  "SearchableModel": "42LC2RR ",
  "ModelName": "42LC2RR",
  "ModelID": 490578,
  "Name": "LG 42 Television 42LC2RR",
  "Desctription": "fffff",
  "Image": "1/4/9/8/18278941c",
  "MinPrice": 9400.0,
  "MaxPrice": 9400.0,
  "StoreAmounts": 1,
  "AuctionAmounts": 0,
  "Popolarity": 3,
  "ViewScore": 0.0,
  "ReviewAmount": 2,
  "ReviewScore": 45,
  "Sog": "E-TV",
  "SogID": 1,
  "IsModel": true,
  "Manufacrurer": "LG",
  "ParamsList": [
    "1994267",
    "46570",
    "4134",
    "4132",
    "4118",
    "46566",
    "4110",
    "180676",
    "239517",
    "750771",
    "2658507",
    "2658498",
    "46627",
    "4136",
    "169941",
    "169846",
    "145620",
    "169940",
    "141416",
    "3190767",
    "3190768",
    "144720",
    "2300706",
    "4093",
    "4009",
    "1418470",
    "179766",
    "190025",
    "170557",
    "170189",
    "43768",
    "4138",
    "67976",
    "239516",
    "3190771",
    "141195"
  ],
}

where the ParamList each represents a property of the product and in our application we have in cache what each param represents.

when searching for a specific product i would like to count all the returning attributes to be able to add the amount of each item after the search.

After searching lg in televisions category i want to get :

Param:4134 witch is a representative of LCD and the amount :65.

but unfortunately i am getting strange results. only some params are counted and some not. on some searchers where i am getting results back i dont get any amounts back.

i am using the latest stable version of RavenDB.

index :

from doc in docs
from param in doc.ParamsList
select new {Name=doc.Name,Description=doc.Description,SearchNotVisible = doc.SearchNotVisible,SogID=doc.SogID,Param =param}

facet :

 DocumentStore documentStore = new DocumentStore { ConnectionStringName = "Server" };
        documentStore.Initialize();
        using (IDocumentSession session = documentStore.OpenSession())
        {
            List<Facet> _facets = new List<Facet>
                        {
                            new Facet {Name = "Param"}

                        };

            session.Store(new FacetSetup { Id = "facets/Params", Facets = _facets });
            session.SaveChanges();
        }

usage example :

IDictionary<string, IEnumerable<FacetValue>> facets = session.Advanced.DatabaseCommands.GetFacets("FullIndexParams", new IndexQuery { Query = "Name:lg" }, "facets/Params");

i tried many variations without success.

does anyone have ideas what am i doing wrong ?

Thanks

Upvotes: 0

Views: 338

Answers (2)

Duc Nguyen
Duc Nguyen

Reputation: 61

What analyzer you set for "Name" field. I see you search by Name "lg". By default, Ravendb use KeywordAnalyzer, means you must search by exact name. You should set another analyzer for Name or Description field (StandardAnalyzer for example).

Upvotes: 0

Ayende Rahien
Ayende Rahien

Reputation: 22956

Use this index, it should resolve your problem:

from doc in docs
select new {Name=doc.Name,Description=doc.Description,SearchNotVisible = doc.SearchNotVisible,SogID=doc.SogID,Param = doc.ParamsList}

Upvotes: 0

Related Questions