在 Google App Engine 中快速创建动态页面
如果您对所列出的技术不太熟悉,并且想尝试回答这个问题,那么这里有一些有用的链接:
https://github.com/tallstreet/Whoosh-AppEngine
http://packages.python.org/Whoosh/quickstart.html#a-quick-introduction
http://code.google.com/appengine/docs/whatisgoogleappengine.html
现在,我的 Google App Engine 网站上有动态创建的页面。我想使用 Whoosh 对这些动态页面上的所有内容进行全文搜索,最重要的是包括动态内容。
这是我的动态页面之一,使用 Django 模板,GAE 文档中对此进行了解释。如果有人知道如何使用 Whoosh 库正确索引此页面中列出的动态内容,请告诉我。
<!DOCTYPE HTML>
<html>
<head>
<title>World Crises</title>
<meta name="description" content="website description" />
<meta name="keywords" content="website keywords, website keywords" />
<meta http-equiv="content-type" content="text/html; charset=windows-1252" />
<link rel="stylesheet" type="text/css" href="style/style.css" title="style" />
<link rel="stylesheet" type="text/css" href="style/wc.css" title="style" />
<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/gallery.js"></script>
</head>
<body>
<div id="main">
<div id="header">
<div id="logo">
<div id="logo_text">
<!-- class="logo_colour", allows you to change the colour of the text -->
<h1><a href="index">World<span class="logo_colour">Crises</span></a></h1>
<h2>Reporting World Crises since Oct 16th, 2011.</h2>
</div>
</div>
<div id="menubar">
<ul id="menu">
<!-- put class="selected" in the li tag for the selected page - to highlight which page you're on -->
<li><a href="index">Index</a></li>
<li class="selected"><a href="crises">Crises</a></li>
<li><a href="organizations">Organizations</a></li>
<li><a href="people">People</a></li>
</ul>
</div>
</div>
<div id="site_content">
<div id="content">
<!-- insert the page content here -->
{% if crisis %}
<h1>{{ crisis.name }}</h1>
<p></p>
<div>
<h2>Information</h2>
<ul>
{% if crisis.kind_ %} <li>Kind: {{ crisis.kind_ }}</li> {% endif %}
{% if crisis.city or crisis.region or crisis.state or crisis.country or crisis.continent %}
<li>Location:
{% if crisis.city %} {{ crisis.city }} {% endif %}
{% if crisis.region %} {{ crisis.region }} {% endif %}
{% if crisis.state %} {{ crisis.state }} {% endif %}
{% if crisis.country %} {{ crisis.country }} {% endif %}
{% if crisis.continent %} {{ crisis.continent }} {% endif %}
</li>
{% endif %}
{% if crisis.startedOn or crisis.endedOn %}
<li>Date and time:
{% if crisis.startedOn and crisis.endedOn%}
{{ crisis.startedOn }} - {{ crisis.endedOn }}
{% else %}
{% if crisis.startedOn %} {{ crisis.startedOn }} {% endif %}
{% if crisis.endedOn %} {{ crisis.endedOn }} {% endif %}
{% endif %}
</li>
{% endif%}
{% if crisis.deaths or crisis.missing or crisis.numberDisplaced or crisis.groupsAffected %}
<li>Human impact:<ul>
{% if crisis.deaths %} <li>{{ crisis.deaths }} deaths</li> {% endif %}
{% if crisis.missing %} <li>{{ crisis.missing }} missing</li> {% endif %}
{% if crisis.numberDisplaced %} <li>{{ crisis.numberDisplaced }} displaced</li> {% endif %}
{% if crisis.groupsAffected %}
<li>Groups Affected:<ul>
{% for group in crisis.groupsAffected %}
<li>{{ group }}</li>
{% endfor %}
</ul></li>
{% endif %}
</ul></li>
{% endif %}
{% if crisis.damageCost or crisis.unemployment or crisis.collectedDonations or crisis.pledgedDonations or crisis.economicSectorsAffected %}
<li>Economic impact:<ul>
{% if crisis.damageCost %} <li>Cost: {{ crisis.damageCost }}</li> {% endif %}
{% if crisis.unemployment %} <li>Jobs lost: {{crisis.unemployment }}</li> {% endif %}
{% if crisis.collectedDonations %} <li>Donations collected: {{crisis.collectedDonations}}</li> {% endif %}
{% if crisis.pledgedDonations %} <li>Donations pledged: {{crisis.pledgedDonations}}</li> {% endif %}
{% if crisis.economicSectorsAffected %}
<li>Economic sectors affected:<ul>
{% for sector in crisis.economicSectorsAffected %}
<li>{{ sector }}</li>
{% endfor %}
</ul></li>
{% endif %}
</ul></li>
{% endif %}
{% if crisis.resourcesNeeded %}
<li>Resources needed:<ul>
{% for resource in crisis.resourcesNeeded %}
<li>{{ resource }}</li>
{% endfor %}
</ul></li>
{% endif %}
{% if crisis.waysToHelp %}
<li>Ways to help:<ul>
{% for way in crisis.waysToHelp %}
<li>{{ way }}</li>
{% endfor %}
</ul></li>
{% endif %}
{% if links.videos %}
<li>Videos: <ul>
{% for video in links.videos %}
{% if video.url %}
<li><a href="{{video.url}}">
{% if video.title %}
{{video.title}}
{% else %}
{{video.url}}
{% endif %}
</a>
{% if video.description %} - {{ video.description }} {% endif %}</li>
{% endif %}
{% endfor %}
</ul></li>
{% endif%}
{% if links.social %}
<li>Social networks: <ul>
{% for social in links.social %}
{% if social.url %}
<li><a href="{{social.url}}">
{% if social.title %}
{{social.title}}
{% else %}
{{social.url}}
{% endif %}
</a>
{% if social.description %} - {{ social.description }} {% endif %}</li>
{% endif %}
{% endfor %}
</ul></li>
{%endif%}
{% if links.external %}
<li>External links: <ul>
{% for link in links.external %}
{% if link.url %}
<li><a href="{{link.url}}">
{% if link.title %}
{{link.title}}
{% else %}
{{link.url}}
{% endif %}
</a>
{% if link.description %} - {{ link.description }} {% endif %}</li>
{% endif %}
{% endfor %}
</ul></li>
{% endif %}
{% if connections.orgs %}
<li>Organizations:<ul>
{% for org in connections.orgs %}
<li><a href="organization?id={{org.uniqueId}}">{{org.name}}</a></li>
{% endfor %}
</ul></li>
{% endif %}
{% if connections.people %}
<li>People:<ul>
{% for person in connections.people %}
<li><a href="person?id={{person.uniqueId}}">{{person.name}}</a></li>
{% endfor %}
</ul></li>
{% endif %}
</ul>
</div>
{% else %}
<h1>404 Crisis Not Found</h1>
{% endif %}
</div>
{% if links.images %}
<ul class="gallery">
{% for image in links.images %}
{% if image.url %}
<li><a href="#"><img src="{{ image.url }}" {% if image.description %} alt={{image.description}} {% endif %}></a></li>
{% endif %}
{% endfor %}
</ul>
{% endif %}
</div>
<div id="content_footer"></div>
<div id="footer">
</div>
</div>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每当添加新内容时,请使用 Whoosh API 将文档添加到搜索索引,如第二个链接中所述。您可以选择添加渲染模板还是输入数据;当您滚动自己的自定义搜索时,更常见的是执行后者;否则你也可以使用谷歌自定义搜索引擎。
不过,您的数据似乎是高度结构化的,并且大部分是数字的;全文索引可能不是搜索数据的最佳方式。
Use the Whoosh API to add documents to the search index as documented in your second link, whenever new content is added. You can choose whether you add the rendered template or the input data; it's more usual to do the latter when you're rolling your own custom search; otherwise you may as well just use a Google Custom Search Engine.
Your data appears to be pretty highly structured, though, and largely numerical; fulltext indexing may not be the best way to search your data.