可以说我有这个XML:
<images>
<photo>
<thumbImg>images/thumbs/002.jpg</thumbImg>
<filename>002</filename>
</photo>
<photo>
<thumbImg>images/thumbs/008.jpg</thumbImg>
<filename>008</filename>
</photo>
<photo>
<thumbImg>images/thumbs/003.jpg</thumbImg>
<filename>003</filename>
</photo>
<photo>
<thumbImg>images/thumbs/006.jpg</thumbImg>
<filename>006</filename>
</photo>
<photo>
<thumbImg>images/thumbs/005.jpg</thumbImg>
<filename>005</filename>
</photo>
</images>
Run Code Online (Sandbox Code Playgroud)
我想找到文件名值为003的元素,然后找到元素1之前和1之后的元素.这就是我可以获取上一个/下一个功能的数据以及在页面上显示所选图像.我以为这会做到这一点:
$image_id = "003";
$project = $xml_object->xpath("photo[filename='$image_id']");
Run Code Online (Sandbox Code Playgroud)
但是print_r是一个空数组......有没有一个简单的方法用xpath来做这个呢?我想我可以通过循环并将prev/next元素放入临时数组来实现,然后一旦找到它,打破循环并返回临时数据,但我认为xpath可能能够多做一点典雅.
编辑:解决 - 这是兄弟节点更清晰的答案:
// for the one prior
//photo[filename='$image_id']/preceding-sibling::photo[1]
// for the one after
//photo[filename='$image_id']/following-sibling::photo[1]
Run Code Online (Sandbox Code Playgroud) 因此,最好尝试一下并通过一些试验和错误来查看,但我正在尝试找出将非常简单的结构从 mysql 迁移到 mongodb 的最佳方法。假设我在 mysql 中有一个名为“articles”的主表,另外还有两个表,一个名为“categories”,另一个名为“category_linkage”。类别都有一个 ID 和一个名称。文章都有一个ID和其他数据。链接表将文章与类别相关联,因此您可以拥有与每篇文章相关的无限类别。
从 MongoDB 方法来看,仅将属于该文章的文章数据和类别 ID 存储在同一集合中是否有意义,因此只有 2 个数据集合(一个用于文章,一个用于类别)?我的想法是,要从文章中添加/删除类别,您只需在该特定文章文档上更新($pull/$push),不是吗?
我认为我已经习惯了一个关于项目中PHP声明的相当宽松的政策 - 我一直只是用过:
<? // here is my php code ?>
Run Code Online (Sandbox Code Playgroud)
我只是在FastCGI下使用PHP-FPM设置了一个nginx服务器,现在它要求我明确声明:
<?php // here is my php code ?>
Run Code Online (Sandbox Code Playgroud)
有什么方法可以改变吗?(否则我将不得不进入我的项目并找到/替换发生这种情况的所有实例).
我的弹性数据设置有不同的字段:类别,子类别,工具和情绪.我的目标是为所有传递给它的关键字提供完全匹配的结果,并且仅返回与所有关键字匹配的结果.到目前为止,这似乎有效,直到我使用由空格分隔的多个单词组成的关键字,如下所示:
"query": {
"bool": {
"must": [
{
"match": {
"categories": "Electronic"
}
},
{
"match": {
"categories": "Pop"
}
},
{
"match": {
"instruments": "Female Vocal"
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
我在ES中的数据包含以下类型的数据:
[name] => Some Data Name
[categories] => Electronic,Pop
[subcategories] => 1970s,Alternative,Experimental,Retro
[instruments] => Electronic Drums,Male Vocal,Synth
[moods] => Fun,Futuristic,Pulsing,Quirky,Rhythmic
Run Code Online (Sandbox Code Playgroud)
因此,它与乐器领域的"声乐"部分相匹配,但不会与"女声"完全匹配.
这可能是由ES过滤器解决的吗?
编辑:为了解释其他字符,我稍微扩展了示例数据集:
[categories]=>R&B,Dance/House
[instruments] => Electronic Drums,Male Vocal,Synth
[moods] => Fun,Futuristic,Pulsing,Quirky,Rhythmic
Run Code Online (Sandbox Code Playgroud)
因此,可能会使用&符号,斜杠和空格.逗号会将单独的术语分开.
解决了 我最后更多地关注分析器,并意识到我可能需要创建一个自定义的分析器来解释我的关键字的边界.
myesurl/tracks/_settings
{
"index": {
"analysis": {
"tokenizer": {
"comma": {
"type": "pattern", …Run Code Online (Sandbox Code Playgroud) 使用jQuery的position()或offset(),我无法看到图像映射区域的顶部/左侧坐标.它适用于FF,但没有别的 - 没有webkit,IE,Opera.
$('area').bind("click",function(){
alert($(this).position().left);
});
<area shape="rect" coords="14,25,205,150" href="#">
Run Code Online (Sandbox Code Playgroud)
任何人都知道以不同的方式访问这些?通常情况下,我只需要使用坐标和分割(","),但这些页面上有一堆多面的区域.