views:

420

answers:

1

I have a simple config of haystack/solr on my django app:

from the models.py of this app:

class device(models.Model):
    ...
    hostname = models.CharField(max_length=45, help_text="The hostname for this device")
    ...

from the search_sites.py of this app:

class devIndex(indexes.SearchIndex):
    '''Haystack class to allow for indexing device objects in TOMS'''
    text = indexes.CharField(document=True, use_template=True)

from templates/search/indexes/systems_management/device_text.txt fo this app (names all jibe)

...
{{ object.hostname }}
...

The Problem:

a system is named static1.foo.com:

if I search for "static", I get results for all static servers ("static" is in their description fields)

if I search for "static1", I get 0 results

if I search for "static1.foo.com" I get results, including this server.

my question is, why is haystack/solr not matching the "static1" query?

A: 

It's likely an analysis problem. I'd guess you are using the StandardTokenizer in your schema.xml file for this field.

The standard tokenizer tokenizes host names as a single token. (ref: http://www.lucidimagination.com/search/document/CDRG_ch05_5.5.1), so you can only match it with the full host name.

If you want to search by pieces, you'll need to use a different tokenizer. The default text field in the Solr example uses the WhitespaceTokenizer and WordDelimeter filter, which will split the host name. This would allow you to find by the query of 'static1'.

ThoughtfulHacking
Thanks for the input. I see where that is spelled out in the schema.xml from the config.I edited my schema.xml to read as follows:<field name="hostname" type="text" indexed="true" stored="true" multiValued="true"/>I then rebuilt my indexes, but I'm still getting no results on a search for a partial hostname:<response>...<str name="q">static1...<result name="response" numFound="0" start="0"/></response>I can't figure out what (else) I'm missing.
jduncan