KRL 和雅虎本地搜索

发布于 2024-10-09 04:08:53 字数 1148 浏览 7 评论 0原文

我正在尝试在 Kynetx 应用程序中使用雅虎本地搜索。

ruleset avogadro {
  meta {
    name "yahoo-local-ruleset"
    description "use results from Yahoo local search"
    author "randall bohn"
    key yahoo_local "get-your-own-key"
  }
  dispatch { domain "example.com"}
  global {
    datasource local:XML <- "http://local.yahooapis.com/LocalSearchService/V3/localsearch";
  }

  rule add_list {
    select when pageview ".*" setting ()
    pre {
      ds = datasource:local("?appid=#{keys:yahoo_local()}&query=pizza&zip=#{zip}&results=5");
      rs = ds.pick("$..Result");
    }
    append("body","<ul id='my_list'></ul>");
    always {
      set ent:pizza rs;
    }
  }

  rule add_results {
    select when pageview ".*" setting ()
    foreach ent:pizza setting pizza
    pre {
      title = pizza.pick("$..Title");
    }
    append("#my_list", "<li>#{title}</li>");
  }
}

我最终得到的列表是

. [object Object]

“标题”,

{'$t' => 'Pizza Shop 1'}

我不知道如何获取标题。看起来原始 XML 文件中的“文本内容”变成了 {'$t' =>; 'text content'} 和 '$t' 给 pick() 带来了问题。

I'm trying to use Yahoo Local Search in a Kynetx Application.

ruleset avogadro {
  meta {
    name "yahoo-local-ruleset"
    description "use results from Yahoo local search"
    author "randall bohn"
    key yahoo_local "get-your-own-key"
  }
  dispatch { domain "example.com"}
  global {
    datasource local:XML <- "http://local.yahooapis.com/LocalSearchService/V3/localsearch";
  }

  rule add_list {
    select when pageview ".*" setting ()
    pre {
      ds = datasource:local("?appid=#{keys:yahoo_local()}&query=pizza&zip=#{zip}&results=5");
      rs = ds.pick("$..Result");
    }
    append("body","<ul id='my_list'></ul>");
    always {
      set ent:pizza rs;
    }
  }

  rule add_results {
    select when pageview ".*" setting ()
    foreach ent:pizza setting pizza
    pre {
      title = pizza.pick("$..Title");
    }
    append("#my_list", "<li>#{title}</li>");
  }
}

The list I wind up with is

. [object Object]

and 'title' has

{'$t' => 'Pizza Shop 1'}

I can't figure out how to get just the title. It looks like the 'text content' from the original XML file turns into {'$t' => 'text content'} and the '$t' give problems to pick().

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生生漫 2024-10-16 04:08:53

当 XML 数据源和数据集转换为 JSON 时,XML 节点中的文本值将分配给 $t。您可以通过将 pre 块中的 pick 语句更改为“尝试一下”来选择标题文本

title = pizza.pick("$..Title.$t");

,看看是否能解决您的问题。


关于与您要考虑的问题无关的事项的旁注:

1)感谢您分享整个规则集、您遇到的问题以及您的期望。使回答您的问题变得更加容易。

2) 不应更改 AppBuilder 或命令行 gem 为您生成的规则集标识符。当前的标识符

ruleset avogadro {

应该看起来更像

规则集 a60x304 {

3) 您不需要

setting ()

在 select 语句中使用 ,除非您的正则表达式中有一个捕获组

When XML datasources and datasets get converted into JSON, the text value within an XML node gets assigned to $t. You can pick the text of the title by changing your pick statement in the pre block to

title = pizza.pick("$..Title.$t");

Try that and see if that solves your problem.


Side notes on things not related to your question to consider:

1) Thank you for sharing the entire ruleset, what problem you were seeing and what you expected. Made answering your question much easier.

2) The ruleset identifier should not be changed from what AppBuilder or the command-line gem generate for you. Your identifier that is currently

ruleset avogadro {

should look something more like

ruleset a60x304 {

3) You don't need the

setting ()

in the select statement unless you have a capture group in your regular expression

淡莣 2024-10-16 04:08:53

事实证明 pick("$..Title.$t") 确实有效。它看起来很有趣,但确实有效。我猜比小丑帽还没有那么有趣。

name = pizza.pick("$..Title.$t");
city = pizza.pick("$..City.$t");
phone = pizza.pick("$..Phone.$t");
list_item = "<li>#{name}/#{city} #{phone}</li>"

希望我现在就吃点披萨!

Turns out that pick("$..Title.$t") does work. It looks funny but it works. Less funny than a clown hat I guess.

name = pizza.pick("$..Title.$t");
city = pizza.pick("$..City.$t");
phone = pizza.pick("$..Phone.$t");
list_item = "<li>#{name}/#{city} #{phone}</li>"

Wish I had some pizza right now!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文