查詢字串的解析 QueryParser類

2021-04-20 07:45:33 字數 1792 閱讀 5135

在lucene中,這項工作就交給了queryparser類來完成,它的作用就是把各種使用者輸入的符號串轉為乙個內部的query或者乙個query組。雖然lucene提供的api允許使用者建立各種各樣的query(查詢語句),但它同時也允許通過queryparser(查詢分析器)生成各種各樣的query子物件。這使得lucene的查詢功能更加靈活和強大。

queryparser的簡單用法

對於queryparser

queryparser

(

string

f, analyzer

a)

query

parse

(

string

query)

parses a query string, returning a

query.eg

: queryparser parser =newqueryparser(

"name"

, analyzer);

query query1 = parser.parse(

"中國建設銀行"

);

而對於multifieldqueryparser

static 

query

parse

(

string

queries,

string

fields,

analyzer

analyzer)

parses a query which searches on the fields specified.static 

query

parse

(

string

queries,

string

fields,

booleanclause.occur

flags,

analyzer

analyzer)

parses a query, searching on the fields specified.

static 

query

parse

(

string

query,

string

fields,

booleanclause.occur

flags,

analyzer

analyzer)

parses a query, searching on the fields specified. eg

: // 構造布林查詢(可根據你的要求隨意組合)

booleanclause.occur flags =newbooleanclause.occur ;

query query = multifieldqueryparser.parse("北京

奧運會"

,newstring , flags,newstandardanalyzer());

注意:

在使用queryparser對使用者的輸入進行掃瞄時,還需要給它乙個分析器。不過,當對使用者輸入的關鍵字進行分析時的分析器應當與建立索引時的分析器一樣,這樣才能保證分析成功。

查詢字串

在乙個主串中查詢相應的子串,如 abcdwoshidef 中查詢 woshi 方法 該實現的方法是最簡單的模式匹配方法,時間複雜度較高 include iostream using namespace std int searchstring const char str1,const char s...

查詢字串

qstring startwith 判斷乙個字串是否以某個字串開頭,引數 字串,大小寫敏感 qstring str welcome to you str.startswith welcome qt casesensitive 返回true str.startswith you qt casesens...

查詢字串

本身不難,寫到這裡只是乙個備忘錄的作用。假定linux系統中有乙個目錄,其中遞迴的存在若干子目錄。現在需要在這些目錄的檔案中尋找乙個字串marvel。我看到的方法是 find type f exec grep marvel 可是死活就是錯誤 find missing argument to exec...