how to use facet in pysolr

748 views Asked by At

I have successful built a python search app with pysolr. So far I have used two fields: id and title. now i want to push two different versions of titles; the original and the title after removing the stopwords. any ideas? the following code works:

def BuildSolrIndex(solr, trandata):
    tmp = []
    for i, dat in enumerate(trandata):
        if all(d is not None and len(d) > 0 for d in dat):
            d = {}
            d["id"] = dat[0]
            d["title"] = dat[1]
            tmp.append(d)
    solr.add(tmp)
    solr.optimize()
    return solr

but this one does not:

def BuildSolrIndex(solr, trandata):
    tmp = []
    for i, dat in enumerate(trandata):
        if all(d is not None and len(d) > 0 for d in dat):
            d = {}
            d["id"] = dat[0]
            d["title_org"] = dat[1]
            d["title_new"] = CleanUpTitle(dat[1])
            tmp.append(d)
    solr.add(tmp)
    solr.optimize()
    return solr

Any ideas?

EDIT:

bellow is the exception:

Traceback (most recent call last):
    ...
    solr = BuildSolrIndex(solr, trandata)
  File "...", line 56, in BuildSolrIndex
    solr.add(tmp)
  File "build/bdist.linux-x86_64/egg/pysolr.py", line 779, in add
  File "build/bdist.linux-x86_64/egg/pysolr.py", line 387, in _update
  File "build/bdist.linux-x86_64/egg/pysolr.py", line 321, in _send_request
pysolr.SolrError: [Reason: None]
<response><lst name="responseHeader"><int name="status">400</int><int name="QTime">8</int></lst><lst name="error"><str name="msg">ERROR: [doc=...] unknown field 'title_new'</str><int name="code">400</int></lst></response>
1

There are 1 answers

3
NWard On BEST ANSWER

This looks like an issue with your Solr schema.xml, as the exception indicates that "title_new" is not recognized as a valid field. This answer may be of assistance to you: https://stackoverflow.com/a/14400137/1675729

Check to make sure your schema.xml contains a "title_new" field, and that you've restarted the Solr services if necessary. If this doesn't solve your problem, come on back!