weixin_33739541 2019-01-30 17:41 采纳率: 0%
浏览 6

字段长度始终= 1

Following the Reuters Ajax Solr tutorial I'm having an issue getting a fields length. The issue is with the 'template' but I believe it may stem from another js file.

THE TUTORIALS 'TEMPLATE'

template: function (doc) {
    var snippet = '';
    if (doc.text.length > 300) {
      snippet += doc.dateline + ' ' + doc.text.substring(0, 300);
      snippet += '<span style="display:none;">' + doc.text.substring(300);
      snippet += '</span> <a href="#" class="more">more</a>';
    }
    else {
      snippet += doc.dateline + ' ' + doc.text;
    }

    var output = '<div><h2>' + doc.title + '</h2>';
    output += '<p id="links_' + doc.id + '" class="links"></p>';
    output += '<p>' + snippet + '</p></div>';
    return output;
  },

MY 'TEMPLATE'

template: function (doc) {
    var snippet = '';
    if (doc.Solution.length > 200) {
            snippet += doc.Solution.substring(0, 200) + ' ' + doc.date;
            snippet += '<span style="display:none;">' + doc.Solution.substring(200);
            snippet += '</span> <a href="#" class="more">more</a>';
    }
    else {
        snippet += doc.Solution.length + '<br>' + doc.date + '';
    }
    var output = '<div><br><b>' + doc.Problem + '</b><br>';
    output += '' + snippet + '';
    output += ' ID #' + doc.id + '</div>';
    return output;
},

This section is supposed to allow for a 'more' button if a field is over a certain length. With my template, this is my output:

output

My 'Solution' field is a long text field which in my schema for solr (7.5) is defined as text_general.

I have tried String() and .toString but those gave me issues as well.

I'm very new to CS as a whole but it seems that my field is behaving as an array or boolean? In the tutorial they have an older version of solr but the field they get the length on is text_general as well. I'm not exactly sure where I should look next.

PS: this is how the code is structured in the tutorial, a friend of mine was confused because it doesn't all seem to be best practices.

I my setup differs from the tutorial in a few ways, I use my version of JQuery (v3.3.1) and they use some style sheets that I do not.

The <head> of my html doc:

    <title>Testing Solr</title>
    <meta charset="UTF-8">
    <!--style sheets and links in tutorial source code--
    <link rel="stylesheet" href="reuters.css">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/jquery-ui.min.js"></script>
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.24/themes/smoothness/jquery-ui.css">
    <!--my downloaded copy of jquery-->
    <script src="script/jquery.js"></script>
    <!-- mentioned in tutorial -->
    <script src="script/our.js"></script>
    <script src="script/Core.js"></script>
    <script src="script/AbstractManager.js"></script>
    <script src="script/Manager.jquery.js"></script>
    <script src="script/Parameter.js"></script>
    <script src="script/ParameterStore.js"></script>
    <script src="script/AbstractWidget.js"></script>
    <script src="script/ResultWidget.js"></script>

Switched to using their links other than the reuters.css, still displaying 1.

Using console.log(doc.Solution); this is indeed acting as an array.

["solution to unlock    "]
0: "solution to unlock    "
length: 1
__proto__: Array(0)

Adding console.log(doc.text); to the tutorial's ResultWidget.js returns plain text to the console. Whats a likely reason my field is being read as an array when theirs is read as a string?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 AT89C51控制8位八段数码管显示时钟。
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测