问题
I'm about writing a search engine based on Zend Search Lucène.
My objects have many different fields (10 text type), and i would like to know which of these ways is the best. (All fields are unstored, just indexed, I don't need to recover them.)
One big field, (concatenation of many small fields) :
$content = $textfield1 . $textfield2 . $textfield3 . $textfield4 ...
Zend_Search_Lucene_Field::unStored("content", $content);
OR
Many small fields :
Zend_Search_Lucene_Field::unStored("content", $textfield1);
Zend_Search_Lucene_Field::unStored("content2", $textfield2);
Zend_Search_Lucene_Field::unStored("content3", $textfield3);
....
....
Each fields may contain lot of text (about 500 words and more).
回答1:
If the content of these fields is similar, then performance-wise, it's better to have one field than several ones (assuming that most of the time you want to search across all of them).
Lucene stores terms for fields in one big dictionary as concatenation of form {field}{term}
, so if you don't need to treat the fields separately it's better to throw them into one bag. This way, you will have way smaller dictionary (especially, if the terms for these fields are similar) and less disk seeks during the search (the sum of postings list scanned will remain roughly the same).
来源:https://stackoverflow.com/questions/9213092/what-is-better-one-big-field-or-many-small