IndexReader#terms for all fields?


#1

Is it possible to query the index for a TermEnum for all fields in
the index instead of just ?

Thanks,
John


#2

On Apr 9, 2007, at 10:52 AM, John B. wrote:

Is it possible to query the index for a TermEnum for all fields in
the index instead of just ?

Err, I meant to write: “instead of just a single field”


#3

On Apr 9, 2007, at 10:52 AM, John B. wrote:

Is it possible to query the index for a TermEnum for all fields in
the index instead of just a single field?

Anyone have any experience with this? Judging from past discussion on
this list it seems like IndexReader#terms doesn’t get used very much.

John


#4

On Apr 12, 2007, at 9:25 AM, David B. wrote:

def print_all_terms(index)
  index.field_infos.each do |field_info|
    field = field_info.name
    index.reader.terms(field).each {|term, freq| puts "# 

{field}:#{term}"}
end
end

David-- thanks, this example is very helpful, but one strange
problem: it seems that FieldInfo does not have a ‘name’ method, and
as far as I can tell there is no way to access the name of the field
represented. What am I missing?

Thanks,
John


#5

On Apr 13, 2007, at 11:02 AM, John B. wrote:

one strange problem: it seems that FieldInfo does not have a ‘name’
method, and
as far as I can tell there is no way to access the name of the field
represented. What am I missing?

I just upgraded to the newest ferret, and now .name works.

Thanks (again),
John


#6

On 4/11/07, John B. removed_email_address@domain.invalid wrote:

On Apr 9, 2007, at 10:52 AM, John B. wrote:

Is it possible to query the index for a TermEnum for all fields in
the index instead of just a single field?

Anyone have any experience with this? Judging from past discussion on
this list it seems like IndexReader#terms doesn’t get used very much.

Here is an example looping over all the terms in an index;

require 'rubygems'
require 'ferret'

def print_all_terms(index)
  index.field_infos.each do |field_info|
    field = field_info.name
    index.reader.terms(field).each {|term, freq| puts 

“#{field}:#{term}”}
end
end

index = Ferret::I.new
[
  {:one => 'one', :two => 'one two three'},
  {:three => 'some knew terms', :four => 'the fourth field'}
].each {|doc| index << doc}

print_all_terms(index)

Hope that helps.

Dave