what is the difference between TermQuery and QueryParser in Lucene 6.0?

后端 未结 2 879
广开言路
广开言路 2021-01-07 03:44

There are two queries,one is created by QueryParser:

QueryParser parser = new QueryParser(field, analyzer);
Query query1 = parser.parse(\"Lucene\");
<         


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-07 04:19

    The QueryParser parses the string and constructs a BooleanQuery (afaik) consisting of BooleanClauses and analyzes the terms along the way.

    The TermQuery does NOT do analysis, and takes the term as-is. This is the main difference.

    So the query1 and query2 might me equivalent (in a sense, that they provide the same search results) if the field is the same, and the QueryParser's analyzer is not changing the term.

提交回复
热议问题