Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Solr4.7 grouping query how to use facet

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "solr4.7 grouping query facet how to use", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use solr4.7 grouping query facet.

Solr calls the result of a query for navigation purposes facet. It does not modify the query result information, but adds count information to the query results according to classification, and then users make further queries according to count information, such as the query list on Taobao, which will show the number of query results related to different categories.

For example, search for digital cameras, in the search results bar will be listed according to the manufacturer, resolution and other dimensions, here the manufacturer, the resolution is a facet.

Then under the manufacturer, there will be nikon, canon, sony and other brands, which is called constraints.

The next step is to list the current navigation path according to your choice, which is called breadcrumb.

There are several facet types for solr:

Ordinary facet, such as establishing fact from the dimension of manufacturer's brand

When querying facet, for example, when querying according to the price, multiple ranges will be set according to the price, such as 0-10, 10-20, 20-30, etc.

Date facet is also a special range query, such as facet by month.

The main advantage of facet is that it can combine search conditions arbitrarily to avoid invalid search and improve the search experience.

Facet is specified by parameters when querying. such as

Write this in http api:

Quote

& facet=true&facet.field=manu

The java code solrj reads as follows:

Query.setFacet (true); / / whether to group query query.setRows (0); / / set the number of returned results to 0 query.addFacetField ("region"); / / increase the grouping field Q query.addFacetField ("theme"); / / add the grouping field q QueryResponse rsp = server.query (query); / / fetch the result FacetField facetField = rsp.getFacetField ("region"); List counts = null If (facetField! = null) {counts = facetField.getValues (); if (counts! = null) {for (Count count: counts) {if (count.getCount ()! = 0) {listRegion.add (count.getName () + "(" + count.getCount () + "));}} map.put (" region ", listRegion);} FacetField facetFieldTheme = rsp.getFacetField (" theme ") List countsTheme = null; if (facetFieldTheme! = null) {countsTheme = facetFieldTheme.getValues (); if (countsTheme! = null) {for (Count count: countsTheme) {if (count.getCount ()! = 0) {listTheme.add (count.getName () + "(" + count.getCount () + "));} map.put (" theme ", listTheme);}}

The result returned by xml is as follows:

17 12 12 9 4

The facet result can be obtained from the java code as follows:

List facetFields = queryResponse.getFacetFields ()

To add facet query to an existing query, you can write:

SolrQuery.addFacetQuery ("quality: [* TO 10]")

For example, if you facet the price according to the specified range, you can add the facet suffix as follows:

Quote

& facet=true&facet.query=price: [* TO 100]

& facet.query=price: [100 TO 200]; & facet.query= [price: 200 TO 300]

& facet.query=price: [300 TO 400]; & facet.query= [price: 400 TO 500]

& facet.query=price: [500 TO *]

If you want to do a further search for products with prices between 400 and 500, you can write this (using solr's filtering query):

Quote

Http://localhost:8983/solr/select?q=camera & facet=on&facet.field=manu&facet.field=camera_type & fq=price: [400 to 500]

Notice that the facet field here no longer contains price

If you make a further query on the type here, the query statement can be written as follows:

Quote

Http://localhost:8983/solr/select?q=camera & facet=on&facet.field=manu & fq=price: [400 to 500] & fq=camera_type:SLR

Usage scenarios of facet:

1. Category navigation

two。 Automatic prompt, with the help of a support for multi-value tag field.

3. You also need to use a tag field to rank the most popular keywords.

At this point, I believe you have a deeper understanding of "solr4.7 grouping query facet how to use", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report