Sunday, January 31, 2010

Faceting and Multifaceting syntax in Solr 1.4

Introduction


So you've installed Solr 1.4 and you've managed to get some data indexed. Now you're ready to have some fun with faceting. Faceting is basically just filtering the results of a search without effecting the relevance score. Sites such as ebay use faceting to help narrow down the results of a generic search like TV, to give you options such as 32" wide-screen LCD etc.


 

It makes for a very pleasant user experience. It's one of the main reasons to use Solr and Solr makes this process very easy. There are actually 3 types of faceting. In this post I'm only going to talk about "field faceting". Once you've mastered "field faceting", the other 2 types ("query faceting" and "date faceting") are very easy and the basic Solr Wiki will be enough for you to get going.


Field Faceting


Now when you're indexing data in Solr, it's best to use the "text" field type, as this applies lots of filters which will help sort out plurals, remove white space etc. However when it comes to faceting, the values returned will be the values after the filters have been applied. Therefore it's best to create new versions of any fields you wish to facet.



You can use the copyfield keyword to make this process very easy.

For example if you have a field called county

Now, when you index county, Solr will use the text field for searching and the string field for displaying the facet results.

Lets get faceting

First up you'll need to turn on the faceting as it's turned off by default.

http://localhost:8080/solr/select/?q=*%3A*&rows=0&facet=on

To facet on a field, all you have to do is use the facet.field=fieldname

http://localhost:8080/solr/select/?q=*%3A*&rows=0&facet=on&facet.field=fcounty

You can apply extra keywords to: limit the results

http://localhost:8080/solr/select/?q=*%3A*&rows=0&facet=on&facet.field=fcounty&facet.limit=3

or even page the results

http://localhost:8080/solr/select/?q=*%3A*&rows=0&facet=on&facet.field=fcounty&facet.limit=5&&facet.offset=5
  

You can sort the results by number descending (Default)

http://localhost:8080/solr/select/?q=*%3A*&rows=0&facet=on&facet.field=fcounty&facet.sort=count

or alphabetical

http://localhost:8080/solr/select/?q=*%3A*&rows=0&facet=on&facet.field=fcounty&facet.sort=lex
 

You can make it so Solr only brings back facets with a minimum number of results:

http://localhost:8080/solr/select/?q=*%3A*&rows=0&facet=on&facet.field=fcounty&facet.mincount=10
  

for more information see solr wiki

Multifaceting

On a website i've worked on we used multifaceting, Solr has a bit of a clunky syntax to support this, but it works and works well.. so who cares :) Lets say I want to apply a filter (fq) on Kent as a county

http://localhost:8080/solr/select/?q=*%3A*&rows=0&facet=on&facet.field=fcounty&fq=fcounty:Kent
 

When you apply the above filter you can see that the other counties get a facet count of 0. This is single faceting and works well. To get multifaceting to work you need to tell solr to exclude the filter (fq) when it works out the facet counts. To do this you can use the ex and tag key words. When you do this you'll notice that the counts for the other facet's come back now, and the filter has still been applied to the results (numFound is still 11).

http://localhost:8080/solr/select/?q=*%3A*&version=2.2&start=0&rows=0&indent=on&facet=on&facet.field={!ex=fcounty}fcounty&fq={!tag=fcounty}fcounty:Kent
 

You can apply as many filter queries as you want now by ORing them together. So if i wanted to filter on Kent OR Cambridgeshire, you can do that as follows:

http://localhost:8080/solr/select/?q=*%3A*&version=2.2&start=0&rows=0&indent=on&facet=on&facet.field={!ex=fcounty}fcounty&fq={!tag=fcounty}fcounty:Kent%20OR%20Cambridgeshire

See how the numFound has gone up from 11 to 18

Conclusion

Now using Solr you can create a really rich user experience with searches and give ebay a run for it's money. Enjoy.

328 comments:

  1. Great! Saved me some research time on this. Especially helpful with the multifaceting.

    ReplyDelete
  2. Thanks N. Glad you liked it. Faceting is great fun.. and it's a really cool way to see what you're index looks like.

    ReplyDelete
  3. Really good Post on how to do Multifaceting with SolrNet here: http://bugsquash.blogspot.com/2010/03/low-level-solrnet.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+bugsquash+%28Bug+squash%29

    ReplyDelete
  4. Congratulations for your post!!!

    I think it is really useful, but I have several problems to obtain a "distinct" query using faceting. I have made tests with faceting but it doesn't run correctly, I would like to know if is possible to use faceting to make a distinct in a query. Could you help me please?????

    Thank you so much.

    ReplyDelete
  5. Hi, this post of stackoverflow might help you out:

    http://stackoverflow.com/questions/2814000/how-to-select-distinct-field-values-using-solr

    ReplyDelete
  6. Yes, thank you for your reply. I had seen this post before, and later the yours but I have problems to make a distinct in solr. It doesn't run correctly using faceting. I suppose I am not doing the correct process. Like the example said, this query: //localhost:8983/solr/select/?q=*%3A*&rows=0&facet=on&facet.field=txt
    must return a query like SELECT
    DISTINCT txt
    FROM
    my_table;
    but this isn't the case, because the request to solr doesn't return the field text in any case.
    Could you help me? any suggestion is grateful.
    Thanks

    ReplyDelete
  7. I have a task of integrating solr with ofbiz. eventhough I tried many times, I am not successful. could you please guide me with steps

    ReplyDelete
  8. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
    Java Training in Chennai

    ReplyDelete
  9. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete
  10. Thank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straight forward and to the point.
    mcdonalds.gutscheine | startlr.com | saludlimpia.com

    ReplyDelete
  11. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.
    or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

    ReplyDelete
  12. Good post and I like it very much. By the way, anybody try this increase app downloads? I do not how to use.

    ReplyDelete
  13. Nice tutorial. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful. Keep sharing on updated tutorials…
    python course in pune | python course in chennai | python course in Bangalore

    ReplyDelete
  14. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
    excel advanced excel training in bangalore | Devops Training in Chennai

    ReplyDelete
  15. Does your blog have a contact page? I’m having problems locating it but, I’d like to shoot you an email. I’ve got some recommendations for your blog you might be interested in hearing.


    AWS Training in Pune | Best Amazon Web Services Training in Pune

    ReplyDelete
  16. Laminated Doors manufacturer in hubli
    Thanks for giving great kind of information. So useful and practical for me. Thanks for your excellent blog, nice work keep it up thanks for sharing the knowledge.

    ReplyDelete
  17. led lawn lights in delhi
    Thanks for giving great kind of information. So useful and practical for me. Thanks for your excellent blog, nice work keep it up thanks for sharing the knowledge.

    ReplyDelete
  18. This comment has been removed by the author.

    ReplyDelete
  19. Nice blog..! I really loved reading through this article. Thanks for sharing such a amazing post with us and keep blogging...

    Article submission sites
    Education

    ReplyDelete
  20. All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.
    Java training in Chennai | Java training institute in Chennai | Java course in Chennai

    ReplyDelete
  21. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Java training in Chennai

    Java training in Bangalore

    ReplyDelete
  22. Very inspiring post and very impressed to me. I want to more post related to this concept. I would you like to thanks for the grand post and keep it up...
    Ethical Hacking Course in Chennai
    Hacking Course in Chennai
    Certified Ethical Hacking Course in Chennai
    Ethical Hacking Training in Chennai
    Ethical Hacking Course

    ReplyDelete
  23. Our line by line lyrics generator is great for writing and fine-tuning songs and raps, especially when you want them to rhyme. Unlike our other song lyrics.

    ReplyDelete
  24. This is quite educational arrange. It has famous breeding about what I rarity to vouch. Colossal proverb.
    This trumpet is a famous tone to nab to troths. Congratulations on a career well achieved. This arrange is synchronous s informative impolites festivity to pity. I appreciated what you ok extremely here 


    Selenium training in bangalore
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training

    ReplyDelete
  25. Make your luck smile, go to the website of the online casino BGAOC and win without a hitch. good casino machine games Take the winnings constantly and without restrictions.

    ReplyDelete
  26. Nice post. Thanks for sharing! I want people to know just how good this information is in your article. It’s interesting content and Great work.
    Thanks & Regards,
    VRIT Professionals,
    No.1 Leading Web Designing Training Institute In Chennai.

    And also those who are looking for
    Web Designing Training Institute in Chennai
    SEO Training Institute in Chennai
    Photoshop Training Institute in Chennai
    PHP & Mysql Training Institute in Chennai
    Android Training Institute in Chennai

    ReplyDelete
  27. You are doing a great job. I would like to appreciate your work for good accuracy
    Regards,
    Selenium Training Institute in Chennai | Selenium Testing Training in chennai

    ReplyDelete
  28. This is the exact information I am been searching for, Thanks for sharing the required infos with the clear update and required points. To appreciate this I like to share some useful information regarding Microsoft Azure which is latest and newest,

    Regards,
    Ramya

    Azure Training in Chennai
    Azure Training Center in Chennai
    Best Azure Training in Chennai
    Azure Devops Training in Chenna
    Azure Training Institute in Chennai
    Azure Training in Chennai OMR
    Azure Training in Chennai Velachery
    Azure Online Training
    Azure Training in Chennai Credo Systemz

    ReplyDelete
  29. Being new to the blogging world I feel like there is still so much to learn. Your tips helped to clarify a few things for me as well as giving..
    Selenium Training in Chennai | SeleniumTraining Institute in Chennai

    ReplyDelete
  30. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...

    Education
    Technology

    ReplyDelete
  31. I feel happy about and learning more about this topic. keep sharing your information regularly for my future reference. This content creates new hope and inspiration within me. Thanks for sharing an article like this. the information which you have provided is better than another blog.
    IELTS Coaching in Dwarka

    ReplyDelete
  32. Great efforts put it to find the list of articles which is very useful to know, Definitely will share the
    same to other forums.

    Check out : big data training in velachery
    big data analytics training and placement
    big data training in chennai chennai tamilnadu
    big data workshop in chennai

    ReplyDelete
  33. It’s interesting content and Great work. Definitely, it will be helpful for others. I would like to follow your blog. Keep post

    Check out:
    best hadoop training in omr
    hadoop training in sholinganallur
    best institute for big data in chennai
    big data hadoop course in chennai with placement

    ReplyDelete
  34. A bewildering web journal I visit this blog, it's unfathomably heavenly. Oddly, in this present blog's substance made purpose of actuality and reasonable. The substance of data is informative
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  35. A bewildering web journal I visit this blog, it's unfathomably heavenly. Oddly, in this present blog's substance made purpose of actuality and reasonable. The substance of data is informative
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  36. An astounding web diary I visit this blog, it's inconceivably magnificent. Strangely, in this current blog's substance made point of fact and sensible. The substance of information is instructive.
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  37. This is really an amazing article. Your article is really good and your article has always good thank you for information

    โปรโมชั่นGclub ของทางทีมงานตอนนี้แจกฟรีโบนัส 50%
    เพียงแค่คุณสมัคร Gclub กับทางทีมงานของเราเพียงเท่านั้น
    ร่วมมาเป็นส่วนหนึ่งกับเว็บไซต์คาสิโนออนไลน์ของเราได้เลยค่ะ
    สมัครสมาชิกที่นี่ >>> Gclub online

    ReplyDelete
  38. This comment has been removed by the author.

    ReplyDelete
  39. Excellent Post as always and you have a great post and i like it

    เว็บไซต์คาสิโนออนไลน์ที่ได้คุณภาพอับดับ 1 ของประเทศ
    เป็นเว็บไซต์การพนันออนไลน์ที่มีคนมา สมัคร Gclub Royal1688
    และยังมีเกมส์สล็อตออนไลน์ 1688 slot อีกมากมายให้คุณได้ลอง
    สมัครสมาชิกที่นี่ >>> Gclub Royal1688

    ReplyDelete
  40. Appericated the efforts you put in the content of DevOps .The Content provided by you for DevOps is up to date and its explained in very detailed for DevOps like even beginers can able to catch.Requesting you to please keep updating the content on regular basis so the peoples who follwing this content for DevOps can easily gets the updated data.
    Thanks and regards,
    DevOps training in Chennai
    DevOps course in chennai with placement
    DevOps certification in chennai
    DevOps course in Omr

    ReplyDelete
  41. I think things like this are really interesting. I absolutely love to find unique places like this. It really looks super creepy though!!

    Check out : big data hadoop training cost in chennai | hadoop training in Chennai | best bigdata hadoop training in chennai | best hadoop certification in Chennai

    ReplyDelete

  42. شركة تركيب طارد الحمام بالمدينة المنورة
    وجود أعشاش الحمام على أسطح المنازل يؤدي لانتشار أنواع مختلفة من الحشرات الضارة و إن لم يكن هناك سبب لطرد الحمام سوى جلب الحشرات الضارة لكان هذا السبب كافي لقرار تسريب الحمام للحشرات لأنها العدو الأول لأي مبنى و يعمل الجميع على مكافحتها إذاً حتى لو كنا نعشق الحمام فلا بد من تسريبه من المنزل تجنباً لانتشارها في المنزل وبالرغم من أن العالم كله يعد الحمام رمزاً للسلام و المحبة إلا أن تواجد الحمام بالمنزل له أضرار متعددة و هذا ما يجعل الجميع يلجئ لشركة تركيب طارد الحمام بالمدينة المنورة للمساعدة في التخلص منه بأسرع وقت و نوفر للجميع طوارد الحمام الحديثة للتخلص من وجودة في المنزل نهائياً .

    ReplyDelete
  43. Outstanding blog thanks for sharing such wonderful blog with us ,after long time came across such knowlegeble blog. keep sharing such informative blog with us.
    hadoop training in chennai cost
    hadoop certification training in chennai
    big data hadoop course in chennai with placement
    big data training in chennai

    ReplyDelete
  44. Nice blog.
    Thanks for sharing Digital marketing training in Bangalore
    120+ hrs of in-class training
    practically on Live Projects.

    ReplyDelete
  45. They're produced by the very best degree developers who will be distinguished for your polo dress creating. You'll find polo Ron Lauren inside exclusive array which include particular classes for men, women.
    python training in bangalore

    ReplyDelete
  46. A befuddling web diary I visit this blog, it's incredibly grand. Strangely, in this present blog's substance made motivation behind fact and sensible. The substance of information is instructive
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete

  47. Excellent blog I visit this blog it's really informative. By reading your blog, I get inspired and this provides useful information.

    Check out:
    Selenium course fees in chennai
    Best Selenium training in chennai
    Selenium training courses in chennai
    Selenium training courses in chennai

    ReplyDelete
  48. I am looking for and I love to post a comment Python classes in punethat "The content of your post is awesome" Great work!

    ReplyDelete
  49. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab Python classes in pune your rss feed to stay informed of any updates.

    ReplyDelete
  50. I have gone through your blog post, nice blog it’s very helpful and I really thankful for you.
    we provide best services autocad classes in Bhopal as well as CPCT training in bhopal we provide service ,
    projector repairing also done by us.
    autocad in bhopal
    3ds max classes in bhopal
    CPCT Coaching in Bhopal
    java coaching in bhopal
    Autocad classes in bhopal
    Catia coaching in bhopal

    ReplyDelete
  51. Thank you for excellent article.You made an article that is interesting.
    Tavera car for rent in coimbatore|Indica car for rent in coimbatore|innova car for rent in coimbatore|mini bus for rent in coimbatore|tempo traveller for rent in coimbatore|kodaikanal tour package from chennai

    Keep on the good work and write more article like this...

    Great work !!!!Congratulations for this blog

    ReplyDelete
  52. Your content is very impressive and thanks for sharing this article. its very useful.
    asset management courses online

    ReplyDelete
  53. The article is so informative. This is more helpful for our
    software testing training online
    best selenium online training in chennai. Thanks for sharing

    ReplyDelete
  54. TreasureBox is operated by a group of young, passionate, and ambitious people that are working diligently towards the same goal - make your every dollar count, as we believe you deserve something better.
    Check out the best
    cheap outdoor furniture nz
    rattan outdoor furniture nz
    headboard nz

    ReplyDelete
  55. Just seen your Article, it amazed me and surpised me with god thoughts that eveyone will benefit from it. It is really a very informative post for all those budding entreprenuers planning to take advantage of post for business expansions. You always share such a wonderful articlewhich helps us to gain knowledge .Thanks for sharing such a wonderful article, It will be deinitely helpful and fruitful article.
    Thanks
    DedicatedHosting4u.com

    ReplyDelete
  56. Such a wonderful blog on Python .Your blog having almost full information about
    Python .Your content covered full topics of Python ,that it cover from basic to higher level content of
    Python .Requesting you to please keep updating the data about Python in upcoming time if there is some addition.
    Thanks and Regards,
    Python tution in Chennai .
    Python workshop in chennai.
    Python training with certification in Chennai.

    ReplyDelete
  57. Keep up the good work. Looking forward to view more from you.

    ReplyDelete
  58. Download and install Vidmate App which is the best HD video downloader software available for Android. Get free latest HD movies, songs, and your favorite TV shows.

    ReplyDelete

  59. Get the most advanced Python Course by Professional expert. Just attend a FREE Demo session.
    For further details call us @ 9884412301 | 9600112302
    Python training in chennai | Python training in velachery

    ReplyDelete
  60. Download and install Vidmate App which is the best HD video downloader software available for Android. Get free latest HD movies, songs, and your favorite TV shows.

    ReplyDelete
  61. Download and install Vidmate App which is the best HD video downloader software available for Android. Get free latest HD movies, songs, and your favorite TV shows.

    ReplyDelete
  62. Its really an Excellent post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog. Thanks for sharing....

    software Providers
    erp software
    crm software
    best software company in chennai
    software company in india
    Top software company in chennai

    ReplyDelete


  63. Get the most advanced AWS Course by Professional expert. Just attend a FREE Demo session.
    For further details call us @ 9884412301 | 9600112302
    AWS training in chennai | AWS training in velachery

    ReplyDelete
  64. Thank you for providing the valuable information …

    If you want to connect with AI (Artificial Intelligence) World

    as like

    Python Training Certification

    related more information then meet on EmergenTeck Training Institute .

    Thank you.!

    ReplyDelete
  65. Hi,

    Thanks for sharing information please keep sharing more Details related and visit again in future for information.

    Again Thanks


    Best honeymoon place in himachal

    Himachal Pradesh is synonymous with scenic beauty, serene landscape, & adventure sports. Literally. “Himachal means” the land of snow. Situated in the western Himalaya, Himachal Pradesh has several hill stations which are the most appropriate destination to find respite from the scorching summer heat. Here’s a list of the 17 best places to visit in Himachal Pradesh on your trip to the land of the Himalayas


    Best honeymoon place in himachal
    Best tourist place in delhi
    best honeymoon place in kerala
    best tourist place in goa
    best tourist places in jharkhand
    places to visit in uttar pradesh
    honeymoon destinations in india
    most romantic honeymoon destinations in india
    five star hotels in delhi
    five star hotels in delhi list
    list of all 5 star hotels in delhi
    5 star hotels in delhi near airport
    hotel in delhi
    hotels in delhi near railway station

    ReplyDelete
  66. Nice Post. If you wish to get study abroad in any course. The below information will suit you.
    Skolarrssolutions
    Mbbs in Russia
    Mbbs in UK
    Mbbs in Malaysia

    ReplyDelete
  67. Download latest audio and video file fromvidmate

    ReplyDelete
  68. An overwhelming web journal I visit this blog, it's unfathomably amazing. Unusually, in this present blog's substance made inspiration driving truth and reasonable. The substance of data is enlightening
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  69. Thank you for excellent article.You made an article that is interesting.
    Tavera car for rent in chennai|Indica car for rent in chennai|innova car for rent in chennai|mini bus for rent in chennai|tempo traveller for rent in chennai
    Keep on the good work and write more article like this...
    innova car rental chennai|Tavera car rental chennai
    Great work !!!!Congratulations for this blog

    ReplyDelete
  70. An overwhelming web journal I visit this blog, it's unfathomably amazing. Unusually, in this present blog's substance made inspiration driving truth and reasonable. The substance of data is enlightening
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  71. thanks for your information really good your work web design company in velachery

    ReplyDelete
  72. thanks for your information really good and very nice web design company in velachery

    ReplyDelete
  73. Usually I never comment on blogs but your article is so convincing that I never stop myself to say something about it. You’re doing a great job Man,Keep it up.
    study in uk from india

    ReplyDelete