Solr Faceting result with more than just count - solr

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

Related

Solr roll up query

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"

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

Can Solr use field values of a known document in a query?

I would like to perform a Solr search using the values of certain fields of an indexed document which I can identify by its id. With MLT this is somehow possible, but I would prefer a regular query parser. Can I somehow use subqueries to inject the result of a subquery into the main query?
For example, let's say I have indexed information about books into solr, where each document represents a book, with an id, title and author field. At query time I have only the document id availible and I would like to search for books by the same author in a single step. Is this possible without using MLT?
You can use JOIN.
http://HOST:PORT/CORE/select?q={!join from=author to=author}id:<ID>

Get possible facet fields with search results

I'm working on improving search which is powered by solr for my e-commerce project. So search queries are performed into Solr and results are returned by Solr.
This is working fine. Now I need to offer a facet on the search results. The first could be category this is easy to implement as Category is common to all product and in the query I make I just enable facet and pass category as facet field.
However, for different nature of products there could be different products and they have few facets defined for them.
I'm clueless as how would I know them in advance and pass it in solr search query? Does solr return all facet field by some queries along with the search results? If yes, how?
If no, then what could be the correct way to proceed further.
Pass all Unique Facet Field Name on which you want to make facet filtering, and you will get all records that have facet field.
Define all the static fieldnames in your facet query search, if there are no hits you will not get any results back for that field.
Pass all the possible fields(on which u need faceting) in Facet Field with facet.mincount=1.. so, you'll get only those fields which has at-least one occurrence in your solr data
http://<hostname>:<portname>/solr/<core_name>/select?q:<fieldname>:<value>&fq=<field_name>:<value>&fl=<field1>,<field2>,<fieldn>&start=0&rows=10&facet=true&facet.field=<field1>&facet.field=<field2>&facet.field=<fieldn>&facet.mincount=1

Solr stats facet left out some values

I want to facet over products in Solr and want to retrieve statistics about the categories.
My schema has got a field called categories, a multiValued field.
the problem is, that the statistics left out a bunch of categories. Am I wrong with following query? Obviously, but how do I make it right? Pleeeease help, I'm despairing.
q=*:*&rows=0&stats=true&stats.field=product_id&rows=0&stats.facet=categories
The query looks fine, the problem is that it's faceting on a multiValued field:
http://wiki.apache.org/solr/StatsComponent
Computing statistics using stats.facet over a multi-valued field does
not work properly.
https://issues.apache.org/jira/browse/SOLR-1782
Hope this helps!

Resources