Apache Solr nGram分组问题

时间:2019-03-05 12:44:06

标签: solr

我将ngram分组时遇到问题。我的查询是

http://localhost:8983/solr/archiveCore/select?group.field=strSO&group=true&q=strSO%3A*&rows=2147483647&start=0&wt=json&indent=true&fl=strSO

它在

之类的网络浏览器(chrome)中向我显示正确的结果
{
  "responseHeader":{
    "status":0,
    "QTime":51,
    "params":{
      "q":"strSO:*",
      "indent":"true",
      "fl":"strSO",
      "start":"0",
      "rows":"2147483647",
      "wt":"json",
      "group.field":"strSO",
      "group":"true"}},
  "grouped":{
    "strSO":{
      "matches":112559,
      "groups":[{
          "groupValue":"EV11777-01",
          "doclist":{"numFound":53,"start":0,"docs":[
              {
                "strSO":"EV11777-01"}]
          }},
        {
          "groupValue":"EV15872-01",
          "doclist":{"numFound":1829,"start":0,"docs":[
              {
                "strSO":"EV15872-01"}]
          }},
        {
          "groupValue":"EV16143-02",
          "doclist":{"numFound":929,"start":0,"docs":[
              {
                "strSO":"EV16143-02"}]
          }},
        {
          "groupValue":"E896759-01",
          "doclist":{"numFound":888,"start":0,"docs":[
              {
                "strSO":"E896759-01"}]
          }},
        {
          "groupValue":"E893257-02",
          "doclist":{"numFound":1250,"start":0,"docs":[
              {
                "strSO":"E893257-02"}]
          }},
        {
          "groupValue":"EV16232-02",
          "doclist":{"numFound":999,"start":0,"docs":[
              {
                "strSO":"EV16232-02"}]
          }},
        {
          "groupValue":"EV12473-01",
          "doclist":{"numFound":1545,"start":0,"docs":[
              {
                "strSO":"EV12473-01"}]
          }},
        {
          "groupValue":"E896479-01",
          "doclist":{"numFound":1016,"start":0,"docs":[
              {
                "strSO":"E896479-01"}]
          }},
        {
          "groupValue":"EV12455-02",
          "doclist":{"numFound":1299,"start":0,"docs":[
              {
                "strSO":"EV12455-02"}]
          }},
        {
          "groupValue":"EV12459-02",
          "doclist":{"numFound":1250,"start":0,"docs":[
              {
                "strSO":"EV12459-02"}]
          }},
        {
          "groupValue":"E876243-01",
          "doclist":{"numFound":1238,"start":0,"docs":[
              {
                "strSO":"E876243-01"}]
          }},
        {
          "groupValue":"E874707-02",
          "doclist":{"numFound":1116,"start":0,"docs":[
              {
                "strSO":"E874707-02"}]
          }},
        {
          "groupValue":"EV12648-02",
          "doclist":{"numFound":1025,"start":0,"docs":[
              {
                "strSO":"EV12648-02"}]

但是在Java中不起作用。我将查询放在我的项目jquery中,而ngram什么也没显示。我不明白为什么它什么都没给我显示。它在网络浏览器上运行良好。

这是我的用于配置ngram的schema.xml

<fieldType name="text_ngram" class="solr.TextField" positionIncrementGap="100" stored="false" multiValued="true">
<analyzer type="index">
<tokenizer class="solr.NGramTokenizerFactory" minGramSize="2" maxGramSize="20"/>    
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.EdgeNGramTokenizerFactory" minGramSize="2" maxGramSize="20"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>

任何人都可以帮助我解决此问题吗?

这是我的jquery代码

<script>
$(function() {
var URL_PREFIX = "http://localhost:8983/solr/archiveCore/select?q=strSO:*";
var URL_SUFFIX = "&group.field=strSO&group=true&rows=2147483647&start=0&wt=json&indent=true&fl=strSO";
$("#searchBoxstrSO").autocomplete({
source : function(request, response) {
var URL = URL_PREFIX + $("#searchBoxstrSO").val() + URL_SUFFIX;
$.ajax({
url : URL,
success : function(data) {
var docs = JSON.stringify(data.response.docs);
var jsonData = JSON.parse(docs);
response($.map(jsonData, function(value, key) {
return {
label : value.strSO
}
}));
},
dataType : 'jsonp',
jsonp : 'json.wrf'
});
},
minLength : 1
})
});
$(function() {
var URL_PREFIX = "http://localhost:8983/solr/archiveCore/select?q=strSO:";
var URL_MIDDLE = "OR strSO_ngram:";
var URL_SUFFIX = "&group.field=strSO&group=true&rows=2147483647&start=0&wt=json&indent=true&fl=strSO";
$("#ngramBoxstrSO").autocomplete(
{
source : function(request, response) {
var searchString = "\"" + $("#ngramBoxstrSO").val() + "\"";
var URL = URL_PREFIX + searchString + URL_MIDDLE
+ searchString + URL_SUFFIX;
$.ajax({
url : URL,
success : function(data) {
var docs = JSON.stringify(data.response.docs);
var jsonData = JSON.parse(docs);
response($.map(jsonData, function(value, key) {
return {
label : value.strSO
}
}));
},
dataType : 'jsonp',
jsonp : 'json.wrf'
});
},
minLength : 1
})
});
</script>

0 个答案:

没有答案