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

<tfoot id='PDWkA'></tfoot>

    • <bdo id='PDWkA'></bdo><ul id='PDWkA'></ul>
      1. <i id='PDWkA'><tr id='PDWkA'><dt id='PDWkA'><q id='PDWkA'><span id='PDWkA'><b id='PDWkA'><form id='PDWkA'><ins id='PDWkA'></ins><ul id='PDWkA'></ul><sub id='PDWkA'></sub></form><legend id='PDWkA'></legend><bdo id='PDWkA'><pre id='PDWkA'><center id='PDWkA'></center></pre></bdo></b><th id='PDWkA'></th></span></q></dt></tr></i><div id='PDWkA'><tfoot id='PDWkA'></tfoot><dl id='PDWkA'><fieldset id='PDWkA'></fieldset></dl></div>

      2. <legend id='PDWkA'><style id='PDWkA'><dir id='PDWkA'><q id='PDWkA'></q></dir></style></legend>

        Lucene OR 使用布尔查询进行搜索

        时间:2023-09-29

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

        <tfoot id='RtO5R'></tfoot>
          <bdo id='RtO5R'></bdo><ul id='RtO5R'></ul>

                <tbody id='RtO5R'></tbody>
                <legend id='RtO5R'><style id='RtO5R'><dir id='RtO5R'><q id='RtO5R'></q></dir></style></legend>
                <i id='RtO5R'><tr id='RtO5R'><dt id='RtO5R'><q id='RtO5R'><span id='RtO5R'><b id='RtO5R'><form id='RtO5R'><ins id='RtO5R'></ins><ul id='RtO5R'></ul><sub id='RtO5R'></sub></form><legend id='RtO5R'></legend><bdo id='RtO5R'><pre id='RtO5R'><center id='RtO5R'></center></pre></bdo></b><th id='RtO5R'></th></span></q></dt></tr></i><div id='RtO5R'><tfoot id='RtO5R'></tfoot><dl id='RtO5R'><fieldset id='RtO5R'></fieldset></dl></div>
                • 本文介绍了Lucene OR 使用布尔查询进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个包含多个字段的索引,其中一个是一个字符串字段,我在其中存储产品的类别名称......例如电子产品"、家庭"、花园"等

                  I have an index with multiple fields, one of which is a string field in which I store category names for a product... such as "Electronics", "Home", "Garden", etc

                  new StringField("category_name", categoryName, Field.Store.YES)); //categoryName is a value such as "Electronics"
                  

                  我正在执行布尔查询以按名称、价格和类别查找产品,但我不确定如何进行 OR 搜索以便同时查询两个类别.

                  I am performing a Boolean query to find products by name, price, and category but I'm not sure how to do an OR search so that I can query for two categories at the same time.

                  我当前的查询如下所示:

                  My current query looks like this:

                  String cat = "Electronics"
                  TermQuery catQuery = new TermQuery(new Term("category_name", cat));
                  bq.add(new BooleanClause(catQuery, BooleanClause.Occur.MUST)); // where "bq" is the boolean query I am adding to, I tried .SHOULD but that didn't help either
                  

                  这适用于一个类别搜索,但我不确定如何搜索电子产品或家庭"这两个类别.

                  this works fine for a one category search, but I am not sure how to search "Electronics OR Home" which would be two categories.

                  推荐答案

                  你可以这样写:

                  BooleanQuery categoryQuery = new BooleanQuery();
                  TermQuery catQuery1 = new TermQuery(new Term("category_name", "Electronics"));
                  TermQuery catQuery2 = new TermQuery(new Term("category_name", "Home"));
                  categoryQuery.add(new BooleanClause(catQuery1, BooleanClause.Occur.SHOULD));
                  categoryQuery.add(new BooleanClause(catQuery2, BooleanClause.Occur.SHOULD));
                  bq.add(new BooleanClause(categoryQuery, BooleanClause.Occur.MUST));
                  

                  这篇关于Lucene OR 使用布尔查询进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Solr 中的查询超时 下一篇:简单使用 Solr 时如何解决“锁定获取超时"?

                  相关文章

                  最新文章

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

                  1. <i id='UEAlC'><tr id='UEAlC'><dt id='UEAlC'><q id='UEAlC'><span id='UEAlC'><b id='UEAlC'><form id='UEAlC'><ins id='UEAlC'></ins><ul id='UEAlC'></ul><sub id='UEAlC'></sub></form><legend id='UEAlC'></legend><bdo id='UEAlC'><pre id='UEAlC'><center id='UEAlC'></center></pre></bdo></b><th id='UEAlC'></th></span></q></dt></tr></i><div id='UEAlC'><tfoot id='UEAlC'></tfoot><dl id='UEAlC'><fieldset id='UEAlC'></fieldset></dl></div>
                    <legend id='UEAlC'><style id='UEAlC'><dir id='UEAlC'><q id='UEAlC'></q></dir></style></legend>

                      <bdo id='UEAlC'></bdo><ul id='UEAlC'></ul>

                    1. <tfoot id='UEAlC'></tfoot>