Solr roll up query - solr

I have a specific query with SOLR that I cannot seem to find a solution for. I have an index full of products and sku's. A product has multiple sku's and every sku has 1 product. I want to perform a search against my SKU's only, group by the parent product and return just the details of the parent product (but not the details of the items).But, I want the facets to represent the original list of items. Is this possible with SOLR today? and what version is this available at?

I think it is possible, my suggestion is to design your core so that the document represent only one SKU, or one item. So, your Unique Id will be the SKU Id. Then you need a productId that is not unique and could have the same value for SKUs that have the same parent product.
You can also de-normalize product details across all documents. So, when you return the details of the item, you also have the details of the produce with it.
The trick here on the query is to use grouping, or field collapsing feature in Solr.
See more details here: https://wiki.apache.org/solr/FieldCollapsing
But as a start I suggest setting these values in the query:
Set group=true (this will enable grouping)
Set group.field=productId (to group, or collapse items by productId)
Set group.facet=false (to include details of all items in facet counts)
So, this will enable you to search across all items, return results grouped by ProductId, and facet numbers will be applied to all items.
This is not a new feature, if you have any Solr 3.3, or 4.x you should be able to use grouping.

You could use :
"sort":"map(special_price,1,99999,special_price,price) desc"
"sort":"map(special_price,1,99999,special_price,price) asc"

Related

Solr: ordering by a multi valued field

I need to create a new collection on my Solr 6.1.0 cluster where every row is a content and every content can belong to one or many categories, which are specified in a multivalued field categories.
In my web app the user can search by categories, and if wanted it can even group results by category. If it wants to order by category, what about the contents which belong to more than one category?
In this case, the search results page should show the same content more times in different categories. I don't want the web application to filter and order results because in this case, it should ask Solr for every row (I know this is not advised for bad performance), so is there a way to let Solr make this? For example, repeating the same content in two categories if a flag is enabled or if I am asking Solr to sort by category?
Until now I bypassed the problem cloning one record for every category and specifying the category ID in a single int field. But this is not optimized, because in this case my index is much bigger than it could be, and every content metadata a part of category is just the same for every content, and because of this I would like to have 1 content = 1 Solr record.

Solr faceted search building widgets

We want to build a faceted search within our application. For example, if we have quantity field whose values range from 1-20 for 2000 records. We need to allow the user to filter by those values.
To, accomplish this we are planning to extract the quantity field sort, eliminate duplicate records and build a widget on the left hand side of the screen, so the user can select what we need.
Is there a way to get this faceted criteria from Solr or any better way to implement it.
This is what Solr calls a Facet, and is enabled using facet=true
&facet=true&facet.field=quantity
.. will give you a facet entry back in the response, containing a count for each unique value in the quantity field. When the user clicks a quantity link, apply a fq for that particular quantity value, such as fq=quantity:4.
You can use facet.sort to determine if the facet should be sorted by hits (most popular quantity first) or alphabetical.
Multi-Select Facets and Local Params might also be useful, if you want to still show the original counts while allowing the user to drill down into the selection when applying an fq with the selected quantity as a criteria.

How to approach a hierarchical search in Solr?

I'm trying to understand how to approach search requirements I have.
The first one is a normal product search that I know Solr can handle appropriately, where you search for a term and Solr returns relevant documents.
The second one is a search for products within a certain category. I have a hierarchical structure in my database that consists in a category with many subcategories and those have products.
The thing is, when some very specific words are searched for, the first approach shouldn't be used, instead a search for a category should be done and only products within that category should be returned, which for me is a very basic SQL query (select * from products where categoryId = 1000).
Does Solr should or can be used in the second case? If so, what is the normal approach to use?
Besides what #Mysterion proposed of filter queries you should take a look at Solr Facets which gives you very powerful catogory-like searching.
You also might want to consider multivalue field for categoryParentIds which will contain the parent categories that the product is in and thus combined with filter query and or facets will get your parent category searching.
Yes, you could use similar approach in Solr, by attributing your products with categoryId and later, while searching add filter query similiar to SQL, categoryId:10000
For more info about filter query, take a look here - http://wiki.apache.org/solr/CommonQueryParameters#fq

Solr: one of each in all categories

I have product index at solr, product has category field and I need to select one product (better would be random) from each category, how query would look like?
if you are looking for sql group by feature,
with solr 3.3 on-wards,
it has the similar feature called FieldCollapsing
Field Collapsing collapses a group of results with the same field value down to a single (or fixed number) of entries. For example, most search engines such as Google collapse on site so only one or two entries are shown, along with a link to click to see more results from that site. Field collapsing can also be used to suppress duplicate documents.

Solr Faceting result with more than just count

This is my requirment:
I have a list of products indexed in Solr and categoryid, category name and category alias are MultiValued fields.
I would like to do faceting on category but want the faceting result to have all categoryID, CategoryName and Category Alias along with the count number.
Is this possible? Or I have to do faceting only for CategoryID and with another request or query to our SQL server database get the rest of the information of that CategoryID?
If a slight increase in index size doesn't matter to you, you're able to change the schema, and you're able to do a full reindex, then add a new field 'categoryFacet' for this. This new field would hold the information you described in your question.
Most likely, you'll solve this by editing the SELECT statement you use for indexing.
Base on the set up in solrconfig,xml, you get back a list of facet value and count. When you select a facet, you'll get back results with all fields you defined in the schema.xml. I'm not aware of anything would allow facet to return more than facet value and count. What's your goal? Is it to display categoryName, categoryId and categoryAlias together as facet to end user? or is it something else? It'll be easier for people to help you if you state your goal clearly. I'm not sure if you checkout the wiki for facet already.
http://wiki.apache.org/solr/SimpleFacetParameters#facet

Resources