# Indexed\_search\_engine: index multiple fields

**URL:** <https://www.ruby-forum.com/t/indexed-search-engine-index-multiple-fields/53721>\
**Category:** Engines\
**Created:** [February 14, 2006, 12:59am UTC](https://www.ruby-forum.com/t/indexed-search-engine-index-multiple-fields/53721 "2006-02-14T00:59:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshua\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@joshua\_s](https://www.ruby-forum.com/u/joshua_s)\
**Post date:** [February 14, 2006, 12:59am UTC](https://www.ruby-forum.com/t/indexed-search-engine-index-multiple-fields/53721/1 "2006-02-14T00:59:40Z")

</div>

Does anyone know of a way to index multiple fields in this engine? I’ve  
tried making an array from the field list, but it doesn’t seem to work.

Any help would be appreciated.

Thanks  
Josh

---

<div class="post-metadata">

**Author:** ![joshua\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@joshua\_s](https://www.ruby-forum.com/u/joshua_s)\
**Post date:** [February 14, 2006, 1:34am UTC](https://www.ruby-forum.com/t/indexed-search-engine-index-multiple-fields/53721/2 "2006-02-14T01:34:29Z")

</div>

I figured it out. All that was necessary was to create two entries for  
an indexable record, one for each field I wanted to index. Then, the  
array is built in the ‘update\_index’ call, not the IndexableRecord.new  
call.

For example, it would look like this:

```
  index_text = IndexableRecord::IndexData.new(@document.text, url,

```

@document.name)  
index\_comment = IndexableRecord::IndexData.new(@document.comment,  
url, @document.name)  
IndexableRecord.index\_records([index\_text, index\_comment])

---

<div class="post-metadata">

**Author:** ![joshua\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@joshua\_s](https://www.ruby-forum.com/u/joshua_s)\
**Post date:** [February 14, 2006, 5:13am UTC](https://www.ruby-forum.com/t/indexed-search-engine-index-multiple-fields/53721/3 "2006-02-14T05:13:07Z")

</div>

Yep. That will do it. I wonder, looking at your code, however, if  
there  
isn’t an refactoring in order for IndexData. It seems wrong to have 2  
IndexData records for the same URL and title.

What if you could do something like:

index\_data = IndexableRecord::IndexData.new(url, @document.name)  
index\_data \<\< @document.text  
index\_data \<\< @document.comment

If it’s useful, I’ll put it on the TODO list.

Lance

On 14 Feb 2006 00:34:16 -0000, Joshua S. \<

---

<div class="post-metadata">

**Author:** ![joshua\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@joshua\_s](https://www.ruby-forum.com/u/joshua_s)\
**Post date:** [February 15, 2006, 6:45am UTC](https://www.ruby-forum.com/t/indexed-search-engine-index-multiple-fields/53721/4 "2006-02-15T06:45:05Z")

</div>

Hi Josh

Thanks for the offer. I’ve actually got the code about 99% there  
already.  
I hope to have a release out this week with relevant changes. I’ll be  
sure  
to keep you (and the list) posted.

Lance

On 14 Feb 2006 18:21:32 -0000, Joshua S. \<

---

<div class="post-metadata">

**Author:** ![joshua\_s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@joshua\_s](https://www.ruby-forum.com/u/joshua_s)\
**Post date:** [February 14, 2006, 7:24pm UTC](https://www.ruby-forum.com/t/indexed-search-engine-index-multiple-fields/53721/5 "2006-02-14T19:24:40Z")

</div>

Lance,

I think that would be great. Would there be a way that I could pass an  
array of attributes in? Like this:

index\_data \<\< [@document.text, @document.comment, @document.note, etc]

Or something such as that. I’d be more than happy to help out with  
anything you need, I’m still fairly new, but could hack around some if  
you needed it.

Josh
