久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='jlBY8'></tfoot>

    <i id='jlBY8'><tr id='jlBY8'><dt id='jlBY8'><q id='jlBY8'><span id='jlBY8'><b id='jlBY8'><form id='jlBY8'><ins id='jlBY8'></ins><ul id='jlBY8'></ul><sub id='jlBY8'></sub></form><legend id='jlBY8'></legend><bdo id='jlBY8'><pre id='jlBY8'><center id='jlBY8'></center></pre></bdo></b><th id='jlBY8'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='jlBY8'><tfoot id='jlBY8'></tfoot><dl id='jlBY8'><fieldset id='jlBY8'></fieldset></dl></div>
    • <bdo id='jlBY8'></bdo><ul id='jlBY8'></ul>

  1. <legend id='jlBY8'><style id='jlBY8'><dir id='jlBY8'><q id='jlBY8'></q></dir></style></legend>

    <small id='jlBY8'></small><noframes id='jlBY8'>

    1. 如何使用 QueryParser 執行包含特殊字符的 lucene 查

      How to perform a lucene query containing special character using QueryParser?(如何使用 QueryParser 執行包含特殊字符的 lucene 查詢?)
    2. <tfoot id='0XQek'></tfoot>

    3. <i id='0XQek'><tr id='0XQek'><dt id='0XQek'><q id='0XQek'><span id='0XQek'><b id='0XQek'><form id='0XQek'><ins id='0XQek'></ins><ul id='0XQek'></ul><sub id='0XQek'></sub></form><legend id='0XQek'></legend><bdo id='0XQek'><pre id='0XQek'><center id='0XQek'></center></pre></bdo></b><th id='0XQek'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='0XQek'><tfoot id='0XQek'></tfoot><dl id='0XQek'><fieldset id='0XQek'></fieldset></dl></div>

      • <legend id='0XQek'><style id='0XQek'><dir id='0XQek'><q id='0XQek'></q></dir></style></legend>
        • <bdo id='0XQek'></bdo><ul id='0XQek'></ul>

                <tbody id='0XQek'></tbody>

                <small id='0XQek'></small><noframes id='0XQek'>

                本文介紹了如何使用 QueryParser 執行包含特殊字符的 lucene 查詢?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                事情就是這樣.我有一個存儲在索引中的詞,其中包含特殊字符,例如'-',最簡單的代碼是這樣的:

                Here is the thing. I have a term stored in the index, which contains special character, such as '-', the simplest code is like this:

                Document doc = new Document();
                doc.add(new TextField("message", "1111-2222-3333", Field.Store.YES, Field.Index.NOT_ANALYZED));
                writer.addDocument(doc);
                

                然后我使用 QueryParser 創建一個查詢,如下所示:

                And then I create a query using QueryParser, like this:

                String queryStr = "1111-2222-3333";
                QueryParser parser = new QueryParser(Version.LUCENE_36, "message", new StandardAnalyzer(Version.LUCENE_36));
                Query q = parser.parse(queryStr);
                

                然后我使用搜索器搜索查詢并沒有得到任何結果.我也試過這個:

                And then I use a searcher to search the query and get no result. I have also tried this:

                Query q = parser.parse(QueryParser.escape(queryStr));
                

                仍然沒有結果.

                不使用 QueryParser 而是直接使用 TermQuery 可以做我想做的事,但是這種方式對于用戶輸入文本不夠靈活.

                Without using QueryParser and instead using TermQuery directly can do what I want, but this way is not flexible enough for user input texts.

                我想也許 StandardAnalyzer 做了一些事情來省略查詢字符串中的特殊字符.試了debug,發現字符串被拆分,實際查詢是這樣的:message:1111 message:2222 message:3333".不知道lucene到底做了什么……

                I think maybe the StandardAnalyzer did something to omit the special character in the query string. I tried debug, and I found that the string is splited and the actual query is like this:"message:1111 message:2222 message:3333". I don't know what exactly lucene has done...

                所以如果我想用特殊字符執行查詢,我應該怎么做?我應該重寫分析器還是從默認的繼承查詢分析器?以及如何?...

                So if I want to perform the query with special character, what should I do? Should I rewrite an analyzer or inherit a queryparser from the default one? And how to?...

                更新:

                1 @The New Idiot @femtoRgon,我已經嘗試了問題中所述的 QueryParser.escape(queryStr),但它仍然不起作用.

                1 @The New Idiot @femtoRgon, I've tried QueryParser.escape(queryStr) as stated in the problem but it still doesn't work.

                2 我嘗試了另一種解決問題的方法.我從Tokenizer派生了一個QueryTokenizer,只用空格截取單詞,打包成一個QueryAnalyzer,它派生自Analyzer,最后將QueryAnalyzer傳遞給QueryParser.

                2 I've tried another way to solve the problem. I derived a QueryTokenizer from Tokenizer and cut the word only by space, pack it into a QueryAnalyzer, which derives from Analyzer, and finally pass the QueryAnalyzer into QueryParser.

                現在可以了.最初它不起作用,因為默認的 StandardAnalyzer 根據默認規則(將某些特殊字符識別為拆分器)切割 queryStr,當查詢傳遞到 QueryParser 時,特殊字符已經被 StandardAnalyzer 刪除.現在我使用我自己的方式來剪切 queryStr 并且它只將空格識別為分隔符,因此特殊字符保留在查詢中等待處理,這很有效.

                Now it works. Originally it doesn't work because the default StandardAnalyzer cut the queryStr according to default rules(which recognize some of the special characters as splitters), when the query is passed into QueryParser, the special characters are already deleted by StandardAnalyzer. Now I use my own way to cut the queryStr and it only recognize space as splitter, so the special characters remain into the query waiting for processing and this works.

                3 @The New Idiot @femtoRgon,感謝您回答我的問題.

                3 @The New Idiot @femtoRgon, thank you for answering my question.

                推薦答案

                我不確定這個,但我猜你需要用 轉義 - .根據 Lucene 文檔.

                I am not sure about this , but I guess you need to escape - with . As per the Lucene docs.

                -"或禁止運算符排除包含-"之后的術語的文檔.符號.

                The "-" or prohibit operator excludes documents that contain the term after the "-" symbol.

                再次,

                Lucene 支持對屬于查詢語法一部分的特殊字符進行轉義.當前列表特殊字符為

                Lucene supports escaping special characters that are part of the query syntax. The current list special characters are

                + - &&||!( ) { } [ ] ^ "~ * ?: /

                + - && || ! ( ) { } [ ] ^ " ~ * ? : /

                要轉義這些字符,請在字符前使用 .

                To escape these character use the before the character.

                另外請記住,如果某些字符在 Java 中具有特殊含義,則需要轉義兩次.

                Also remember, some characters you'll need to escape twice if they have special meaning in Java.

                這篇關于如何使用 QueryParser 執行包含特殊字符的 lucene 查詢?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                How to convert Integer to int?(如何將整數轉換為整數?)
                How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                Inconsistent behavior on java#39;s ==(java的行為不一致==)
                Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)
              1. <tfoot id='Uagqn'></tfoot>
                  <bdo id='Uagqn'></bdo><ul id='Uagqn'></ul>

                    • <i id='Uagqn'><tr id='Uagqn'><dt id='Uagqn'><q id='Uagqn'><span id='Uagqn'><b id='Uagqn'><form id='Uagqn'><ins id='Uagqn'></ins><ul id='Uagqn'></ul><sub id='Uagqn'></sub></form><legend id='Uagqn'></legend><bdo id='Uagqn'><pre id='Uagqn'><center id='Uagqn'></center></pre></bdo></b><th id='Uagqn'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Uagqn'><tfoot id='Uagqn'></tfoot><dl id='Uagqn'><fieldset id='Uagqn'></fieldset></dl></div>
                        <tbody id='Uagqn'></tbody>

                    • <legend id='Uagqn'><style id='Uagqn'><dir id='Uagqn'><q id='Uagqn'></q></dir></style></legend>

                          <small id='Uagqn'></small><noframes id='Uagqn'>

                        1. 主站蜘蛛池模板: 欧洲精品在线观看 | 精品乱码一区二区 | 婷婷综合 | 视频一区 亚洲 | 精品视频免费 | 毛片在线免费 | 欧美 日韩 亚洲91麻豆精品 | 欧洲妇女成人淫片aaa视频 | 欧美日韩专区 | 欧美一区二 | 日韩有码一区二区三区 | 欧洲成人午夜免费大片 | 久久人| 亚洲国产成人精品女人久久久 | 羞羞视频免费在线观看 | 视频国产一区 | 国产97视频在线观看 | 亚洲精品视频一区二区三区 | 久久精品欧美一区二区三区不卡 | 色综合一区二区 | 国精产品一区二区三区 | 久久成人18免费网站 | 青娱乐一区二区 | 一级毛片色一级 | 欧美中文字幕一区 | 视频在线亚洲 | 羞羞色视频 | 精品无码久久久久久国产 | 日韩精品成人 | 欧美性tv | 精品国产一区二区在线 | 黄色一级毛片 | 日日操操操 | 国产欧美精品一区 | 91精品国产综合久久久久久 | 西西裸体做爰视频 | 国产乱xxav| 久久一二 | 国产一区二区在线播放 | www.色综合 | 在线毛片网 |