22

Can someone explain what a SpanQuery is, and what are typical use cases for it?

The documentation is very laconic, and keeps mentioning the concept of "span", which I'm not quite sure I get.

erickson
  • 265,237
  • 58
  • 395
  • 493
itsadok
  • 28,822
  • 30
  • 126
  • 171

4 Answers4

18

Spans provide a proximity search feature to Lucene. They are used to find multiple terms near each other, without requiring the terms to appear in a specified order. You can specify the terms that you want to find, and how close they must be. You can combine these span queries with each other or with other types of Lucene queries.

André Laszlo
  • 15,169
  • 3
  • 63
  • 81
erickson
  • 265,237
  • 58
  • 395
  • 493
  • 1
    How is the different to a query with a slop? – Joel Oct 25 '09 at 08:02
  • 1
    This is useful http://www.lucidimagination.com/blog/2009/07/18/the-spanquery/ – Joel Oct 25 '09 at 08:05
  • 3
    Current link for above comment: https://lucidworks.com/blog/the-spanquery/ – Paul Mar 27 '15 at 22:15
  • 3
    @Joel 'query with a slop' can use search-time analyser, but span can't use. span has in_order feature , which is missing in query with slop – Raghu Jun 07 '17 at 06:19
  • The working link I find for spanquery https://massiveprogramming.blogspot.com/2014/10/the-spanquery-lucidworks.html – nantitv Feb 17 '21 at 21:26
5

Found this all about the SpanQuery

André Laszlo
  • 15,169
  • 3
  • 63
  • 81
Joel
  • 29,538
  • 35
  • 110
  • 138
4

A span query is a query that returns infomation about where in a document each match took place. You use the getSpans() method to get the locations.

The following deck of slides (unfortunately in Powerpoint) contain an example: http://www.cnlp.org/apachecon2005/AdvancedLucene.ppt

Vebjorn Ljosa
  • 17,438
  • 13
  • 70
  • 88
2

The javadocs you linked to are for a class in the " org.apache.lucene.search.spans " package. if you had clicked on the "package" link on those javadocs you would have been taken to...

https://lucene.apache.org/core/4_10_0/core/org/apache/lucene/search/spans/package-summary.html

...where the concept of Spans and what a Span is are explained in depth.

André Laszlo
  • 15,169
  • 3
  • 63
  • 81
Hoss
  • 156
  • 6