我正在使用haystack和whoosh作为Django app的后端.
有没有办法查看whoosh生成的索引的内容(以易于阅读的格式)?我想看看哪些数据被编入索引,以及如何更好地理解它是如何工作的.
我有一个简单的设置与django-haystack和嗖嗖引擎.搜索产生19个物体花了我8秒钟.我用django-debug-toolbar确定我有一堆重复的查询.
然后我将我的搜索视图更新为预取关系,以便不会发生重复查询:
class MySearchView(SearchView):
template_name = 'search_results.html'
form_class = SearchForm
queryset = RelatedSearchQuerySet().load_all().load_all_queryset(
models.Customer, models.Customer.objects.all().select_related('customer_number').prefetch_related(
'keywords'
)
).load_all_queryset(
models.Contact, models.Contact.objects.all().select_related('customer')
).load_all_queryset(
models.Account, models.Account.objects.all().select_related(
'customer', 'account_number', 'main_contact', 'main_contact__customer'
)
).load_all_queryset(
models.Invoice, models.Invoice.objects.all().select_related(
'customer', 'end_customer', 'customer__original', 'end_customer__original', 'quote_number', 'invoice_number'
)
).load_all_queryset(
models.File, models.File.objects.all().select_related('file_number', 'customer').prefetch_related(
'keywords'
)
).load_all_queryset(
models.Import, models.Import.objects.all().select_related('import_number', 'customer').prefetch_related(
'keywords'
)
).load_all_queryset(
models.Event, models.Event.objects.all().prefetch_related('customers', 'contracts', 'accounts', 'keywords')
)
Run Code Online (Sandbox Code Playgroud)
但即便如此,搜索仍需要5秒钟.然后我使用了profiler django-debug-toolbar,它给了我这个信息:
据我所知,问题在于haystack/query:779::__getitem__,它被击中两次,每次耗费1.5秒.我浏览过有问题的代码,但无法理解它.那么我从哪里开始呢?
有没有人有使用任何经验django-haystack与whoosh后端?
我希望将它用于分类的实时搜索类型工具.在生产环境中是否足够快/高效以避免设置solr或xapian?
我在MongoDB中建立了一个庞大的银行数据库.我可以轻松地获取此信息并在其中创建索引.例如,我希望能够匹配银行名称'Eagle Bank&Trust Co of Missouri'和'Eagle Bank and Trust Company of Missouri'.以下代码适用于简单模糊这样,但无法实现上述匹配:
from whoosh.index import create_in
from whoosh.fields import *
schema = Schema(name=TEXT(stored=True))
ix = create_in("indexdir", schema)
writer = ix.writer()
test_items = [u"Eagle Bank and Trust Company of Missouri"]
writer.add_document(name=item)
writer.commit()
from whoosh.qparser import QueryParser
from whoosh.query import FuzzyTerm
with ix.searcher() as s:
qp = QueryParser("name", schema=ix.schema, termclass=FuzzyTerm)
q = qp.parse(u"Eagle Bank & Trust Co of Missouri")
results = s.search(q)
print results
Run Code Online (Sandbox Code Playgroud)
给我:
<Top 0 Results for And([FuzzyTerm('name', u'eagle', boost=1.000000, minsimilarity=0.500000, …Run Code Online (Sandbox Code Playgroud) 我需要使用Google App Engine进行全文搜索.我找到了项目Whoosh并且它工作得非常好,只要我使用App Engine开发环境......当我将我的应用程序上传到App Engine时,我得到以下TraceBack.对于我的测试,我使用的是此项目中提供的示例应用程序.我知道我做错了什么?
<type 'exceptions.ImportError'>: cannot import name loads
Traceback (most recent call last):
File "/base/data/home/apps/myapp/1.334374478538362709/hello.py", line 6, in <module>
from whoosh import store
File "/base/data/home/apps/myapp/1.334374478538362709/whoosh/__init__.py", line 17, in <module>
from whoosh.index import open_dir, create_in
File "/base/data/home/apps/myapp/1.334374478538362709/whoosh/index.py", line 31, in <module>
from whoosh import fields, store
File "/base/data/home/apps/myapp/1.334374478538362709/whoosh/store.py", line 27, in <module>
from whoosh import tables
File "/base/data/home/apps/myapp/1.334374478538362709/whoosh/tables.py", line 43, in <module>
from marshal import loads
Run Code Online (Sandbox Code Playgroud)
这是我在Python文件中的导入.
# Whoosh ----------------------------------------------------------------------
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'utils')))
from whoosh.fields import …Run Code Online (Sandbox Code Playgroud) 我正在寻找能够搜索部分术语的文档搜索引擎(如Xapian,Whoosh,Lucene,Solr,Sphinx或其他).
例如,当搜索术语"brit"时,搜索引擎应该返回包含"britney"或"britain"的文档,或者通常包含匹配r的单词的任何文档.*brit*
切向地,我注意到大多数引擎使用TF-IDF(术语频率 - 反向文档频率)或其衍生物,它们基于完整术语而非部分术语.除了TF-IDF之外,还有其他成功实施的技术用于文档检索吗?
我有很多人名(例如"john smith").我想通过名字查找人物.但是,有些查询会拼写错误(例如"jon smth","johnsm ith").是否有任何包含Python绑定的拼写修正库可能会为我找到经过拼写纠正的匹配?
我知道Whoosh和Python-aspell.Whoosh的拼写纠正对我来说并不适用,因为它将正确拼写的集合写入磁盘而不是将其存储在内存中.这使得我的应用程序查找速度太慢.由于代码的结构如何,改变这种行为似乎并不容易.另外,飞快移动不会对不同的角色编辑加权不同,即使"y"更可能与"i"("jim kazinsky" - >"jim kazinski")混淆,而不是'z' .
Aspell与人名不兼容,因为名字通常包含空格--Aspell认为这个词是纠正的基本单位.另外,据我所知,Aspell使用n-gram拼写校正模型,而不是字符编辑距离模型.虽然n-gram模型对于字典词是有意义的,但它对名称不起作用:人们"bob ruzatoxg"和"joe ruzatoxg"有很多共同的罕见三元组,因为它们具有相同的罕见姓氏.但他们显然是不同的人.
我还要提一下,我不能只将每个查询与集合中的所有条目进行比较 - 这太慢了.某些索引需要预先构建.
谢谢!
我对搜索实现很陌生,在我学习的同时忍受我!
所以我的宠物项目是一个食谱站点,每个食谱可以有n个步骤.该模型看起来像:
class Recipe(models.Model):
title = models.CharField(max_length=255)
description = models.TextField()
hotness = models.ForeignKey(Hotness)
recipe_diet = models.ManyToManyField(DietType)
ingredients = models.ManyToManyField(Ingredient, through="RecipeIngredient")
class DietType(models.Model):
diet_type = models.CharField(max_length=50)
description = models.TextField(null=True, blank=True)
class RecipeIngredient(models.Model):
recipe = models.ForeignKey(Recipe)
ingredient = models.ForeignKey(Ingredient)
quantifier = models.ForeignKey(Quantifier)
quantity = models.FloatField()
class RecipeSteps(models.Model):
step_number = models.IntegerField()
description = models.TextField()
recipe = models.ForeignKey(Recipe)
Run Code Online (Sandbox Code Playgroud)
(简称简称)
我想索引所有这些:Recipe,RecipeIngredient,DietType和Steps ... DietType和RecipeIngredient似乎工作正常,但步骤不是.我假设这与'RelatedSearchQuerySet'的使用有关?
这是我的search_indexes.py:
from haystack import indexes
from recipes.models import Recipe
class RecipeIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
title = indexes.CharField(model_attr='title')
ingredients = indexes.MultiValueField(indexed=True, …Run Code Online (Sandbox Code Playgroud) 我已经在网上阅读了入门文档和其他一些示例.这就是我的search_indexes.py看起来像:
from haystack.indexes import *
from haystack import site
from models import Entry
class EntryIndex(SearchIndex):
text = CharField(document=True)
headline = CharField(model_attr='headline')
subheadline = CharField(model_attr='subheadline')
category = CharField(model_attr='category__name')
author = CharField(model_attr='get_author')
email = CharField(model_attr='get_email')
tags = CharField(model_attr='tags')
content = CharField(model_attr='content')
def get_queryset(self):
return Entry.objects.exclude(dt_published=None).order_by('-is_featured', '-dt_published', '-dt_written', 'headline')
site.register(Entry, EntryIndex)
Run Code Online (Sandbox Code Playgroud)
但是当我搜索时,我没有得到任何结果.奇怪的是,如果我使用搜索短语'a'或任何其他单个字母,我会得到看起来像该死的东西中的每一个条目.
无论如何......在我看来,搜索引擎并没有在任何领域寻找.:/
这条线以下的任何东西都不太相关(它有效,相信我):
我的看法:
from haystack.views import SearchView
class CustomSearchView(SearchView):
def __name__(self):
return "CustomSearchView"
def extra_context(self):
return common(self.request)
def search(request):
return CustomSearchView(template='news/search_results.html')(request)
Run Code Online (Sandbox Code Playgroud)
和search_results.html:
{% extends "content.html" %}
{% load tagging_tags %}
{% …Run Code Online (Sandbox Code Playgroud) 我是初创公司的新手编码器,我正在网络主机的目录中实现文档搜索.
我正在比较Lucene/Solr,飞快移动,狮身人面像和Xapian.飞快移动本身就是蟒蛇.但我也想要你的意见.其中有哪些