12

Does facet searching come built in when you setup your schema or do you have to do some things to set this up?

Does it basically work out of the box on all the fields that you have setup to be sortable?

then you just use the fq query syntax and it will return the facet xml along with the search results?

Is there a nice article on this that helped you first time around?

Blankman
  • 259,732
  • 324
  • 769
  • 1,199

5 Answers5

19

Yes, you can facet any indexed field out of the box. However it might not give you the results you expect until you configure faceting fields according to your data types.

Faceting is enabled and used through the facet.* parameters, not fq. fq is used when the user selects a facet value.

Some good Solr tutorials:

Mauricio Scheffer
  • 98,863
  • 23
  • 192
  • 275
  • @Mauricio_Scheffer do you know any project - github or codeplex - that currently have faceted search implemented to benchmark - solr or lucene - ! brgds. – s_h Jan 16 '13 at 11:32
  • 1
    @sebastian_h the proper place to ask that question would be http://lucene.apache.org/solr/discussion.html . But what do you want to benchmark exactly? There are dozens of factors in configuration, querying and schema design that affect Solr/Lucene performance. – Mauricio Scheffer Jan 16 '13 at 14:52
  • @Mauricio_Scheffer thank you for your reply. I´m new on this area consequently I was wondering if any project in C# as eg is available to see an approach implementing solr. brgds! – s_h Jan 16 '13 at 15:57
  • @mauricio_scheffer thank you for the info. great work with solrnet. its recommended to use solrnet 0.4 in beta or work with version 0.3? brgds! – s_h Feb 01 '13 at 17:56
  • 1
    @sebastian_h always go for the latest, even if beta, it's stable. – Mauricio Scheffer Feb 02 '13 at 16:02
10

Yes, Simply add &facet=true&facet.field={fieldname} to your request Url.

Here is another tutorial:Faceting

James Lawruk
  • 30,112
  • 19
  • 130
  • 137
  • 1
    The URL is no longer findable. You can possibly substitute it with http://searchhub.org/2009/09/02/faceted-search-with-solr/ – panza Nov 06 '13 at 16:38
2

The below code in C#, by using SolrNet package. The Facet you can do it on the fields stored in SOLR, make sure its string and doesn't have space for better results. The mincount is for limiting the minimum number to get listed in facet.

        QueryOptions options = new QueryOptions
        {                
            Facet = new FacetParameters
            {
                Queries = new ISolrFacetQuery[]
                {
                    new SolrFacetFieldQuery("field1"),
                    new SolrFacetFieldQuery("field2")
                },
                MinCount = 20
            }
        };

And the below code to get the results, query - is the search entered in front end.

    var result = solr.Query(query, options);
Shan
  • 578
  • 5
  • 18
0

Faceting from Apache solr reference guide.

PVR
  • 885
  • 9
  • 18
0

SolrNet package from Nuget Packages in C# provides a simple way of achieving this. The documentation helps. Here's an example,

public async Task SolrFaceting()
    {
        Console.WriteLine("facets");
        var facetQuery = await _solr.QueryAsync(SolrQuery.All, new QueryOptions
        {
            Rows = 0,
            Facet = new FacetParameters
            {
                Queries = new[]
                {
                    new SolrFacetFieldQuery("FieldName1"),
                    new SolrFacetFieldQuery("FieldName2"),
                    new SolrFacetFieldQuery("FieldName3"),
                    new SolrFacetFieldQuery("FieldName4"),
                },
                Limit = 10

            }
        });

        foreach (var facet in facetQuery.FacetFields["FieldName1"]) {
            Console.WriteLine("{0}: {1}", facet.Key, facet.Value);
        }
        foreach (var facet in facetQuery.FacetFields["FieldName2"]) {
            Console.WriteLine("{0}: {1}", facet.Key, facet.Value);
        }
        foreach (var facet in facetQuery.FacetFields["FieldName3"]) {
            Console.WriteLine("{0}: {1}", facet.Key, facet.Value);
        }
        foreach (var facet in facetQuery.FacetFields["FieldName4"]) {
            Console.WriteLine("{0}: {1}", facet.Key, facet.Value);
        }
    }