Getting facet name plus extra/meta info about a field in Solr - solr

Solr returns each facet as a collection of name/count pairs (wrapped in a FacetField). In my faceted search app I would use these as follows.
Audi (2)
Honda (5)
Mitsubishi (6)
Mercedes Benz (8)
Now I would like to turn this into a list of links. I could create URLs like
http://www.example.com/category=Mercedes%20Benz
That would work, but I would much rather have
http://www.example.com/category=4
That is, I would like to use the database ID of the categories/brands instead of their names.
Can I somehow link fields in Solr, so that I can link the category name to the category ID and have them both returned from my query? Or should I use a multivalued field and store the category name and id together?
Your advice is most welcome :)

I have an idea. You can define a new field which joins category id and category name together. Just like express below.
1_Audi, 2_Honda, 3_Mitsubishi ,4_Mercedes Benz
Faceting on the new field will get result like this,
1_Audi(2)
2_Honda(3)
3_Mitsubishi(4)
4_Mercedes Benz(5)
You can split them laterly to get both category id and name. Name for disply while id for link.

You can check for Solr pivot as well which will return the Category Name and the Category Id as parent child facet hierarchy which in you case will always be one to one match.

Related

Sorting of solr documents based on search term in solr

I would like to sort solr documents based on searched term. For example the search term is "stringABC"
Then the order of the results should be
stringABC,
stringABCxxxx,
xxxxstringABCxxxx
The solr document will contain lot of fileds ex: title, description, path, article No, Product code etc..
And the default field will contain more than one field ex: title, description and path.
So the solr doc will only be returned when the search term satisfied any field from the default field.
Use three fields - one with the exact string, one with a EdgeNgramTokenizer and one with an NgramTokenizer. You can then use qf=field1^10 field2^5 field3 to score hits in these fields according to how you want to prioritize them between each other.

Solr faceted search within a column

I need to a faceted search on a particular column and drill down within its results.
Here is my schema.
State ZipCode PersonName
CA 12345 Tom
CA 12345 Mike
CA 23458 John
CA 23458 Lucy
I tried writing a facet query
http://localhost:8983/solr/query?facet=on&facet.field=State and it facets only based on State.
How do I include Zip code within it, so that I can drill down based on State & Zip code
You can do this two ways, depending on what you want.
If you just want to include a ZipCode facet as well, in addition to the State facet, add another facet.field parameter: &facet.field=ZipCode. That way you'll get facets for both fields in your response. The facets will be modified depending on your query results and filter queries, so if the user selects a State first, the fq= will make the ZipCode facet only return facet values within that state. You might also want to look at Tagging and excluding filters, if you want to show a count of all States, regardless of one being chosen at the moment.
Another option is to use facet.pivot to get a two-dimensional table with facet values; for each state, get the count of the zipcodes in that state. &facet.pivot=State,ZipCode.

how to join and search all the fields in solr?

I have two documents product and seller.
Product: {ID,NAME,DESCRIPTION}
Seller: {ID, PRODUCT_ID, SELLER_NAME, ATTRIBUTE_NAME, ATTRIBUTE_VALUE}
I need to join both of these documents and search all the fields in the seller and product?
So far I'm trying something like {!join from=product_id to=id}seller_name:"Sample-2" . This searches value "Sample-2" in seller_name field of seller document. How can i modify this to search all the fields of product and seller along with join?
Usually you'd implement this by either using copyField-directives to add all the terms into one field and search on that field, or by supplying a qf= parameter to give the fields you'd want to search (with *dismax).
If you're going to do a lot of these you might want to create a separate core and index pre-processed data into that, with copyField directives to create a catch all-field.

Difference between Solr Facet Fields and Filter Queries

I am using SolrMeter to test Apache Solr search engine. The difference between Facet fields and Filter queries is not clear to me. SolrMeter tutorial lists this as an exapmle of Facet fields :
content
category
fileExtension
and this as an example of Filter queries :
category:animal
category:vegetable
categoty:vegetable price:[0 TO 10]
categoty:vegetable price:[10 TO *]
I am having a hard time wrapping my head around it. Could somebody explain by example? Can I use SolrMeter without specifying either facets or filters?
Facet fields are used to get statistics about the returned documents - specifically, for each value of that field, how many returned documents have that value for that field. So for example, if you have 10 products matching a query for "soft rug" if you facet on "origin," you might get 6 documents for "Oklahoma" and 4 for "Texas." The facet field query will give you the numbers 6 and 4.
Filter queries on the other hand are used to filter the returned results by adding another constraint. The thing to remember is that the query when used in filtering results doesn't affect the scoring or relevancy of the documents. So for example, you might search your index for a product, but you only want to return results constrained by a geographic area or something.
A facet is an field (type) of the document, so category is the field. As Ansari said, facets are used to get statistics and provide grouping capabilities. You could apply grouping on the category field to show everything vegetable as one group.
Edit: The parts about searching inside of a specific field are wrong. It will not search inside of the field only. It should be 'adding a constraint to the search' instead.
Performing a filter query of category:vegetable will search for vegetable in the category field and no other fields of the document. It is used to search just specific fields rather than every field. Sometimes you know that the term you want only is in one field so you can search just that one field.

cakephp multiple pagination with same model but different condition

I have a category and products table. In view, I need to list the data in the following way
Category1 title
id product name price (in a table)
Pagination numbers (I will pass the category id here)
Category2 title
id product name price
Pagination numbers
etc
etc
How can I do the pagination for this ? On first pagination click, other paginations should not be changed. Categories are dynamic.
I don't think there is an easy direct cakephp way of doing this. But you can do it. You need is to customize the links so the pass on another variable identifying the parameter and then you have to parse it and do the pagination.
I google it and find the same solution but with a step by step tutorial :D
How to have multiple paginators
Here they use the model name to identify it but you will have to put something like model1, model2, etc so you identify which one is it, or simply numbers or words you need.

Resources