Solr and facet search

后端 未结 5 1260
迷失自我
迷失自我 2021-02-03 10:08

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 th

相关标签:
5条回答
  • 2021-02-03 10:49

    Faceting from Apache solr reference guide.

    0 讨论(0)
  • 2021-02-03 10:55

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

    Here is another tutorial:Faceting

    0 讨论(0)
  • 2021-02-03 10:56

    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);
    
    0 讨论(0)
  • 2021-02-03 11:01

    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:

    • http://lucene.apache.org/solr/tutorial.html
    • http://www.lucidimagination.com/Community/Hear-from-the-Experts/Podcasts-and-Videos/Solr-Tutorial
    0 讨论(0)
  • 2021-02-03 11:05

    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);
            }
        }
    
    0 讨论(0)
提交回复
热议问题