【问题标题】:lucene search query not working in solr4.6lucene 搜索查询在 solr4.6 中不起作用
【发布时间】:2014-04-04 07:01:23
【问题描述】:

我们有数百万条记录。最初我们使用 lucene 来索引数据,但由于 OutofMemeory 异常,决定将数据移动到 solr。下面是我们在 schema.xml 中声明的用于执行索引和搜索操作的字段。

 <field name="product"      type="string"   indexed="true"  stored="true"  multiValued="false" />
 <field name="source"       type="string"   indexed="true"  stored="true"  multiValued="false" />
 <field name="target"       type="string"   indexed="true"  stored="true"  multiValued="false" />
 <field name="pos"          type="string"   indexed="true"  stored="true"  multiValued="false" />
 <field name="company"     type="string"   indexed="true"  stored="true"  multiValued="false" />
 <field name="deprecated"   type="string"   indexed="true"  stored="true"  multiValued="false" />
 <field name="id"           type="string"   indexed="true"  stored="true"  multiValued="false" required="true"/>

我们正在使用 solrj api 来创建 solr 查询。

Solr查询代码:

SolrQuery solrQuery=new SolrQuery();
solrQuery.setQuery("id:*_TB");
solrQuery.setRows(10000);
solrQuery.addFilterQuery(searchStr);//
QueryResponse rsp = httpserver.query(solrQuery);

在 lucene 中,当用户在 UI 中键入短语时,以下查询在精确搜索、模糊搜索等中工作。

EX:- 新品牌推出

用于 lucene 中的精确搜索
searchstr = (source:"abc" OR target:"abc" OR deprecated:"abc") AND company:"tc"

模糊搜索:
searchstr =(来源:新品牌发布~0.7 OR 目标:新品牌发布~0.7 或弃用:新品牌发布~0.7)AND 公司:“bb”

默认搜索

searchstr =(来源:新品牌发布*或目标:新品牌发布*或弃用:新品牌发布*)AND公司:“cc”

现在在 solr 中,上面的查询不起作用。当用户在 UI 中输入上述“新品牌推出”短语时,结果为零。有时我们会遇到 lucene 中不区分大小写的问题。

请告诉我哪里做错了。

【问题讨论】:

    标签: mysql solr


    【解决方案1】:
    1. 您已声明所有字符串类型的字段。字符串字段类型不标记化。你真的想要这种行为吗?

    2. (source:New Brand launched* OR target:New Brand launched* OR deprecated:New Brand launched*) AND company:"cc"
      如果您不在要搜索的文本周围使用双引号,那么它将不是 SOLR 中的短语查询。所以source:New Brand launched* 实际上会被搜索为
      source:New OR defaultField:Brand OR defaultField:launched*
      其中 defaultField 将是 schema.xml 中定义的默认字段,并且将根据 schema.xml 中指定的默认运算符使用 OR/AND。而是搜索source:"New Brand launched"

    通过 SOLR 文档了解更多信息。

    【讨论】:

    • 在我的应用程序中,我想使用类似搜索的短语。例如:我想搜索“New Brand laun*”,应该只得到“新品牌推出”的结果,但正如你提到的,这是在 Source 字段中搜索“New”,其余单词在默认字段中搜索。我想得到我从 SQL 查询中得到的行为,例如:field1 like 'new brand laun*' 或 field2 like ''new brand laun*''。我怎样才能实现这种行为。
    猜你喜欢
    • 2016-01-23
    • 1970-01-01
    • 2022-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-09
    相关资源
    最近更新 更多