Let us look at how we can build our own query parser. We will build a proximity query parser known as SWAN query where SWAN stands for Same, With, Adjacent, and Near. This query parser would use the SWAN relationships between terms to process the query and fetch the results.
Solr provides position-aware queries via phrase slop queries. An example of a phrase slop is
"samsung galaxy"~4 that suggests
galaxy must occur within 4 word positions of each other. However, this does not take care of the SWAN queries that we are looking for. Lucene has support for providing position-aware queries using
SpanQueries. The classes that implement span queries in Lucene are: