Forum: Ferret Missing fields in search result

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D1ef7b749b44dd849d37a1c1fe4e7ab0?d=identicon&s=25 Gregor Melhorn (Guest)
on 2006-03-09 15:13
Hello ferret users,

I have a problem with ferret dropping stored fields in the index.

Not all fields I want to store get stored, so they can be searched, but
can't be retrieved in a search.

Index creation:

INDEX = Index::Index.new(:path => '/home/gregor/wisa/index',
                         :analyzer => Analysis::WhiteSpaceAnalyzer.new)
SR = Index::IndexSearcher(:path => '/home/gregor/wisa/index',
                          :analyzer => Analysis::WhiteSpaceAnalyzer.new)


Storing:

  # initial creation of a lucene index
  def create_index
    # our central INDEX
    index = FerretConfig::INDEX

    # get all Companies, iterate over and index them
    companies = Company.find(:all)
    for company in companies
      doc = Document.new
      doc << Field.new("id",   company.id,           Field::Store::YES,
Field::Index::UNTOKENIZED)
      doc << Field.new("country",
company.company_group.address.country.name, Field::Store::YES,
Field::Index::UNTOKENIZED)
      doc << Field.new("name", company.name,         Field::Store::YES,
Field::Index::UNTOKENIZED)
      doc << Field.new("zip",  company.address.zip,  Field::Store::YES,
Field::Index::UNTOKENIZED)
      doc << Field.new("city", company.address.city, Field::Store::YES,
Field::Index::UNTOKENIZED)
      doc << Field.new("street", company.address.street,
Field::Store::YES, Field::Index::TOKENIZED)
      doc << Field.new("sectorid", company.sector_id, Field::Store::NO,
Field::Index::UNTOKENIZED)
      doc << Field.new("parentsectorid", (company.sector.parent_id ||
""), Field::Store::NO, Field::Index::UNTOKENIZED)
      doc << Field.new("sector", company.sector.name, Field::Store::YES,
Field::Index::UNTOKENIZED)
      doc << Field.new("parentsector",
company.sector.breadcrumb.first.name, Field::Store::YES,
Field::Index::UNTOKENIZED)
      doc << Field.new("districtid", company.district_id,
Field::Store::NO, Field::Index::UNTOKENIZED)
      doc << Field.new("district", company.district.name,
Field::Store::YES, Field::Index::UNTOKENIZED)
      doc << Field.new("sales", sprintf('%010.4f', company.sales),
Field::Store::YES, Field::Index::UNTOKENIZED)
      doc << Field.new("employees", sprintf('%010d', company.employees),
Field::Store::YES, Field::Index::UNTOKENIZED)
      doc << Field.new("codesector", company.code_sector.code,
Field::Store::YES, Field::Index::UNTOKENIZED)
      doc << Field.new("codesectorparent", company.code_sector.parent,
Field::Store::NO, Field::Index::UNTOKENIZED)
      doc << Field.new("codesectorname", company.code_sector.name,
Field::Store::YES, Field::Index::UNTOKENIZED)
      doc << Field.new("cooperation", company.cooperation.to_i.to_s,
Field::Store::YES, Field::Index::UNTOKENIZED)
      doc << Field.new("lastname", company.contact.lastname,
Field::Store::YES, Field::Index::UNTOKENIZED)
      doc << Field.new("firstname", company.contact.firstname,
Field::Store::YES, Field::Index::UNTOKENIZED)
      doc << Field.new("position", company.contact.position,
Field::Store::YES, Field::Index::UNTOKENIZED)
      doc << Field.new("title", company.contact.title,
Field::Store::YES, Field::Index::UNTOKENIZED)
      doc << Field.new("salutation", company.contact.salutation,
Field::Store::YES, Field::Index::UNTOKENIZED)
      doc << Field.new("mail", company.contact.mail, Field::Store::YES,
Field::Index::UNTOKENIZED)
      doc << Field.new("fax", company.fax, Field::Store::YES,
Field::Index::UNTOKENIZED)
      doc << Field.new("phone", company.phone, Field::Store::YES,
Field::Index::UNTOKENIZED)
      doc << Field.new("url", company.url, Field::Store::YES,
Field::Index::UNTOKENIZED)
      doc << Field.new("comments", company.comments, Field::Store::YES,
Field::Index::TOKENIZED)
      doc << Field.new("products", company.products, Field::Store::YES,
Field::Index::TOKENIZED)
      doc << Field.new("state", company.state.name, Field::Store::YES,
Field::Index::UNTOKENIZED)
      doc << Field.new("investorname", company.company_group.name,
Field::Store::YES, Field::Index::UNTOKENIZED)
      doc << Field.new("investorcity",
company.company_group.address.city, Field::Store::YES,
Field::Index::UNTOKENIZED)
      doc << Field.new("investorstreet",
company.company_group.address.street, Field::Store::YES,
Field::Index::TOKENIZED)
      doc << Field.new("investorzip", company.company_group.address.zip,
Field::Store::YES, Field::Index::UNTOKENIZED)
      index << doc
      logger.info "URL: " + doc["url"] # gets url, so doc is ok
    end

    # don't close the index, but be sure to write it to the fs
    index.optimize()
    logger.info "URL 1: " + index[0]["url"] # passed, prints out
correctly
    logger.info "URL 2: " + index[1]["url"] # passed, prints out
correctly
    redirect_to(:action => 'new_index')
  end

Searching:

    if (@conditions != conditions)
      @records = Array.new
      sr = FerretConfig::SR
      sr.reader =
Index::IndexReader.open(Store::FSDirectory.get_directory("/home/gregor/wisa/index"))
      qp = Ferret::QueryParser.new("id", { :analyzer =>
Ferret::Analysis::WhiteSpaceAnalyzer.new(),
                              :wild_lower => false})
      @records = sr.search(qp.parse(conditions))
    end

Search results are correct, but many fields are missing and can't be
accessed. The only fields in the results are

city, name, zip, country, mail, firstname, lastname, id, phone, fax,
street, sector, parentsector

All others are missing....

Hope someone can help me soon, this is getting me crazy.. :-/

Best regards
Gregor
D1ef7b749b44dd849d37a1c1fe4e7ab0?d=identicon&s=25 Gregor Melhorn (Guest)
on 2006-03-09 18:02
resolved: restarting webrick was all I needed to do (apart from some
other stupid errors in the code..) *bangingheadontable*
This topic is locked and can not be replied to.