Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb 如何在SOLRJQuery中进行多词搜索_Mongodb_Solr_Solrj - Fatal编程技术网

Mongodb 如何在SOLRJQuery中进行多词搜索

Mongodb 如何在SOLRJQuery中进行多词搜索,mongodb,solr,solrj,Mongodb,Solr,Solrj,我目前正在为我们的Web应用程序使用SolrJ API。我们需要在应用程序中进行多词搜索。但我不知道怎么做 以下是我们通过在web上搜索开发的代码 HttpSolrClient solr=新的HttpSolrClient(“http://localhost:8983/solr/Test"); SolrQuery query=新的SolrQuery(); query.setQuery(“产品名称:戴尔笔记本电脑*”); 查询设置字段(“产品名称”); query.setStart(0); quer

我目前正在为我们的Web应用程序使用SolrJ API。我们需要在应用程序中进行多词搜索。但我不知道怎么做

以下是我们通过在web上搜索开发的代码

HttpSolrClient solr=新的HttpSolrClient(“http://localhost:8983/solr/Test");
SolrQuery query=新的SolrQuery();
query.setQuery(“产品名称:戴尔笔记本电脑*”);
查询设置字段(“产品名称”);
query.setStart(0);
query.setRows(1000);
QueryResponse response=solr.query(查询);
SolrDocumentList结果=response.getResults();
对于(int i=0;i
但我没有得到任何结果输出。我们的Solr在运行于8983端口的ApacheSolr管理控制台的帮助下合并了一个mongo DB

请帮忙。我对ApacheSolr是新手

更新: 下面是我们创建的schema.xml


身份证件
下面是数据配置.xml


Lucene的JavaDoc中提到了您遇到的问题。为什么是Lucene?Solr的查询语法是Lucene的超集

注意:该字段仅对其直接前面的术语有效,因此查询

标题:做对

将仅在标题字段中找到“Do”。它将在默认字段(本例中为文本字段)中找到“It”和“right”

在您的情况下,只有Dell指向字段product_name,其余的指向配置中定义的默认搜索字段

您想用来绕过此问题的方法称为。因此,你需要用圆括号将进入一个字段的单词括起来,如下所示

SolrQuery query=new SolrQuery();
query.setQuery(“产品名称:(戴尔笔记本电脑*)”);//用(…)
查询设置字段(“产品名称”);
query.setStart(0);
query.setRows(1000);

我们通过删除不需要的引用创建了一个新的schema.xml。这里是我们使用的模式

<schema name="example" version="1.5">

<field name="_version_" type="long" indexed="true" stored="true"/>
<field name="_root_" type="string" indexed="true" stored="false"/>

        <fields>    
        <field name="id" type="long" indexed="true" stored="true" required="true" multiValued="false" /> 
        <field name="product_name" type="string" indexed="true" stored="true" required="true" />
        <field name="product_price" type="" indexed="true" stored="true" required="true" />

    </fields>  
    <uniqueKey>id</uniqueKey>
     <types>
                <fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
                <fieldType name="long" class="solr.TrieLongField" precisionStep="0" omitNorms="true" positionIncrementGap="0" />
                <fieldType name="text_wslc" class="solr.TextField" positionIncrementGap="100">
                        <analyzer type="index">
                                <tokenizer class="solr.WhitespaceTokenizerFactory"/>
                                <filter class="solr.LowerCaseFilterFactory"/>
                        </analyzer>
                        <analyzer type="query">
                                <tokenizer class="solr.WhitespaceTokenizerFactory"/>
                                <filter class="solr.LowerCaseFilterFactory"/>
                        </analyzer>
                </fieldType>
                <fieldType name="tdouble" class="solr.TrieDoubleField" precisionStep="8" positionIncrementGap="0"/>
                <fieldType name="location" class="solr.LatLonType" subFieldSuffix="_coordinate"/>
                <fieldType name="tdate" class="solr.TrieDateField" omitNorms="true" precisionStep="6" positionIncrementGap="0"/>
        <fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" positionIncrementGap="0"/>
     </types>

        <defaultSearchField>product_name</defaultSearchField>

        <!-- we don't want too many results in this usecase -->
        <solrQueryParser defaultOperator="AND"/>

           </schema>

身份证件
产品名称

使用
query.setQuery(“*:*”)运行此操作时,是否会得到任何结果
并注释掉
query.setFields(“产品名称”)?查询
“*:*”
将返回整个索引,以确保您在其中有文档。@切夫,我是在使用“query.setQuery(:”)时得到结果的单词查询工作正常,就像搜索戴尔一样。我要找的是,如果我们搜索“dell laptop”,则会得到同时包含dell和laptop的结果@cheffe我也添加了模式文件。我们使用solr sever file dowloaded中的一个示例创建了这个文件。请检查是否有任何错误。尝试查询
产品名称:(戴尔笔记本电脑)
产品名称:(戴尔笔记本电脑)
产品名称:(戴尔笔记本电脑)
。您已将类型
字符串
用于字段产品名称。该类型区分大小写。感谢您的提示,我们现在重写了整个schema.xml,它的工作记录用于回复。我得到了结果,但它只显示13个输出,而实际使用的mongodb的结果是1000+@cheffe字段分组似乎对“SolrQuery”没有多大影响。“SolrQuery”对象是否有备选方案。不,没有备选方案。这是要使用的对象。当您看到的结果少于预期时,是时候转到solr服务器的/admin页面并修复查询了。我敢肯定,您的产品名称字段分析器存在缺陷。