How to group in Lucene search results?

How to group search results returned by Lucene by fields (similar to SQL Server)?

+5
source share
4 answers

Lucene 3.4 now supports faceted search. When indexing, you specify something additional, and during the search, you search by query and by group.

for the next 3 documents you index with these groups

doc1: monday, 1pm,  3min    
doc2: monday, 1pm,  4min    
doc3: monday, 2pm,  3min

you can search only for the first parameter: Monday and get the value: 3, or you can expand and search for Monday / 1pm and get the value: 2 or set the search depth to 3 and get

monday :3
monday/1pm :2
monday/1pm/3min :1
monday/1pm/4min :1
monday/2pm :1
monday/2pm/3min :1

here is the original example :

But most of all read faceted search

+2
+1

Lucene , : Grouping

(, Solr), .

Lucene 4.0 ( )

+1

, "GROUP BY" SQL "ORDER BY". Lucene , "GROUP BY" Lucene.

However, sorting by fields is quite simple. Make sure that the desired field is indexed, and create an object org.apache.lucene.search.Sortthat will be transferred as part of the search criteria; most search methods have an overload that takes an instance Sort.

If you must implement your own GROUP BY logic with ORDERED BY results, the correct fields are a useful first step.

0
source

All Articles