Solr faceted search building widgets - solr

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.

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 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 do I get the first and last document per SOLR facet, sorted by some field?

I have documents with multiple facets. I have different views on the website I'm creating to view the facet stats.
As well as showing the facet stats, I would like to show example documents from each facet - specifically, the first and last documents ordered by another field.
For example, properties for sale, I want to see the first and last (based on price) for each facet (the facet can be street, area, city, post code etc).
I can solve this by calling SOLR multiple times for each facet, but it seems like something that should be built in and if so, it would reduce roundtrips a LOT. (it would mean probably 2 SOLR calls per page instead of 30 or possibly more)
Instead of faceting, you can look into
https://wiki.apache.org/solr/FieldCollapsing
Then you need to do only two queries with group.sort ASC or DESC on the field by which you want to sort.

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.

Index document "linked" to multiple users

Hi I want to index a Solr Document and tag the document with multiple associated users. I want to enable searches like "give me the documents assocaited with userid 1000,1003...9300 containing the word X. More people will be added to the document during the lifetime of the document. I want to potentially associate thousands of users to one document. There is no need to show the associated users in the results, just for search, will indexing of userid or username be more performant and scalable. What field type would be more performant and scalable, appending to a text field, a multivalued field or any other approach?
I believe that using the userid (as an integer) would be the most performant. (At least from my experience so far). Also, using a multivalued field will allow you to use a filter query on the userid field to help improve the query response time.

Resources