Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #88384
| Path | csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'tutorial': 0.03; 'argument': 0.05; 'encoding': 0.05; 'subject:file': 0.07; 'string': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:How': 0.10; '"from': 0.16; 'experiments': 0.16; 'fine.': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'sizable': 0.16; 'skip:u 50': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'trying': 0.19; 'file,': 0.19; '>>>': 0.22; 'example': 0.22; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'replace': 0.24; 'initial': 0.24; 'question': 0.24; 'query': 0.26; 'header:X -Complaints-To:1': 0.27; 'tried': 0.27; 'correct': 0.29; 'skip:p 30': 0.29; "i'm": 0.30; 'skip:q 20': 0.31; 'file': 0.32; 'actual': 0.34; 'something': 0.35; 'but': 0.35; 'located': 0.36; 'machine.': 0.36; 'subject:?': 0.36; 'should': 0.36; 'expected': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'materials': 0.61; 'simple': 0.61; 'email addr:gmail.com': 0.63; 'skip:w 30': 0.69; 'results': 0.69; 'subject:handle': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: How to handle file in Whoosh? |
| Date | Tue, 31 Mar 2015 15:52:27 +0200 |
| Organization | None |
| References | <23b11937-781e-473b-ba6e-9b5d68b8ebbd@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p57bd93cd.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.19 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.373.1427809979.10327.python-list@python.org> (permalink) |
| Lines | 47 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1427809979 news.xs4all.nl 2841 [2001:888:2000:d::a6]:42762 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:88384 |
Show key headers only | View raw
subhabrata.banerji@gmail.com wrote:
> I am trying to build a search engine, I started with Whoosh. The tutorial
and web based materials are fine. Web has sizable question and answers. The
initial experiments seem going fine. But I want to handle files located in
various parts of my machine. I found "from whoosh.filedb.filestore import
FileStorage", but I am looking for a simple example to start with. I tried
something as below, it may be giving some result but is it going okay? If
any one may please see and correct if required?
>
> >>> txt_file1=open("/python27/whooshtext1.txt","r").read()
> >>> txt_file2=open("/python27/whooshtext3.txt","r").read()
> >>> writer.add_document(title=u"First document", path=
unicode("indexdir"+os.sep+"a"),content=u"txt_file1")
I'm not a whoosh user myself, but if I were to guess:
The content argument should contain the contents of the file, not the
variable name, e. g.:
import io
...
ENCODING = "ascii" # replace with actual encoding of the file
txt_file1 = io.open("/python27/whooshtext1.txt", encoding=ENCODING).read()
...
writer.add_document(
title=u"First document",
path=os.path.join(u"indexdir", u"a"),
content=txt_file1)
> >>> writer.add_document(title=u"Second document", path=
unicode("indexdir"+os.sep+"b"),content=u"txt_file2")
> >>> writer.commit()
> >>> with ix.searcher() as searcher:
> query = QueryParser("content", ix.schema).parse("flood")
> results = searcher.search(query)
> print results
> for result in results:
> print result
>
>
> <Top 0 Results for Term('content', u'flood') runtime=0.000124042337439>
u"flood" is indeed not in the string u"txt_file2" nor the string
u"txt_file1", so that's the expected number of matches.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
How to handle file in Whoosh? subhabrata.banerji@gmail.com - 2015-03-31 06:20 -0700 Re: How to handle file in Whoosh? Peter Otten <__peter__@web.de> - 2015-03-31 15:52 +0200
csiph-web