Migrating from Zend_Lucene to Solr.

瀏覽次數:45 次
跳到第一則未讀訊息

Vasiliy Toporov

未讀,
2011年1月19日 清晨7:21:232011/1/19
收件者:PHP Solr Client
Hello.

In our project (based on Zend Framework) we have to find a replacement
for default Zend_Lucene. Now I'm trying to implement Solr with PHP
Solr Client in it.
We have 2 tables, where we take the data: categories and offers.

In Zend_Lucene addition data to index go that way:

/*Code above we create new index and take data from mysql
And here are the old methods:
offer - is array with query results
*/


$to_index = "{$offer["name"]} {$offer["type"]}
{$offer["description"]}";

$doc = new Zend_Search_Lucene_Document();
$doc->addField( Zend_Search_Lucene_Field::Text('text', $to_index,
"utf-8") );
$doc->addField( Zend_Search_Lucene_Field::Keyword('cat_id',
$offer["cat_id"]) );
$doc->addField( Zend_Search_Lucene_Field::Keyword('type', "offer") );
$doc->addField( Zend_Search_Lucene_Field::Keyword('id',
$offer["id"]) );
$doc->addField( Zend_Search_Lucene_Field::UnIndexed('created',
time()) );

$this->index->addDocument($doc);

/*End of old code*/
The same methods we have for categories/

In Solr and PHP Solr Client, I've changed that code (using default
example schema.xml):

$to_index = "{$category["name"]}";

$doc = new Apache_Solr_Document();
$doc->text = $to_index;
$doc->type = "category";
$doc->id = $category["id"];
$doc->created = time();

try {
$this->solr->addDocuments($doc);
$this->solr->commit();
$this->solr->optimize();
}
catch ( Exception $e ) {
echo $e->getMessage();
}

But search in index gives me 0! I have a suspicion, that Solr doesn't
make proper index. (But there are no bug messages or exeptions during
index creation). Also I'd try to give Solr only text and id poles in
methods/ But result was the same!

What I'm doing wrong?

Donovan Jimenez

未讀,
2011年1月19日 上午11:19:512011/1/19
收件者:php-sol...@googlegroups.com
Step 1, lets make sure you're indexing what you think you are: Do a query for *:* , do you see your document(s) that you indexed (it should return everything in the index). 

Step 2, if you see all expected documents, then I imagine your problem might be either you're not querying the fields you expect to, or they're not indexed as you expect them to be. Does your query use field identifiers or is it relying on the default search field configured in the schema.xml?  If that seems correct, also try adding the debugging parameters to your request to get an idea of what Solr is doing under the hood: http://wiki.apache.org/solr/CommonQueryParameters#Debugging

Hope this helps,
- Donovan


--
You received this message because you are subscribed to the Google Groups "PHP Solr Client" group.
To post to this group, send email to php-sol...@googlegroups.com.
To unsubscribe from this group, send email to php-solr-clie...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/php-solr-client?hl=en.


Vasiliy Toporov

未讀,
2011年1月20日 上午8:01:312011/1/20
收件者:PHP Solr Client
Thank you, Donovan! Your answer and xDebug helped me.
The decision of my problem was very simple:
1) I've made a mistake, when mechanically replaced Zend_Lucene methods
on code from IBM tutorial. The invoke of

try {
$this->solr->addDocuments($doc);
$this->solr->commit();
$this->solr->optimize();
}

code was in the "foreach" loop. So addDocuments method got wrong
parameters (objects instead of array of objects) and commit method
received empty xml.

2) Also I used default schema.xml

$doc->text = $to_index;

That is the mistake, because in xml there were no field "text".
Also I've seen in the schema type of field - dynamicField. "If a field
name is not found, dynamicFields will be used if the name matches any
of the patterns."
Are there any methods in your library to work with that type? Or I
should make changes in schema each time I add custom field to
Apache_Solr_Document?

On Jan 19, 9:19 pm, Donovan Jimenez <donovan.jime...@gmail.com> wrote:
> Step 1, lets make sure you're indexing what you think you are: Do a query
> for *:* , do you see your document(s) that you indexed (it should return
> everything in the index).
>
> Step 2, if you see all expected documents, then I imagine your problem might
> be either you're not querying the fields you expect to, or they're not
> indexed as you expect them to be. Does your query use field identifiers or
> is it relying on the default search field configured in the schema.xml?  If
> that seems correct, also try adding the debugging parameters to your request
> to get an idea of what Solr is doing under the hood:http://wiki.apache.org/solr/CommonQueryParameters#Debugging
>
> Hope this helps,
> - Donovan
>
> > php-solr-clie...@googlegroups.com<php-solr-client%2Bunsu...@googlegroups.com>
> > .

Donovan Jimenez

未讀,
2011年1月20日 上午10:56:462011/1/20
收件者:php-sol...@googlegroups.com
dynamic fields are all based at the solr server, you don't have to do anything special with the client OTHER than have fields that will match one of your dynamic field definitions.  The dynamic fields work by matching field names against a suffix or a prefix. So the field types still have to be predefined before you index, you just have more flexibility in the full field name. For example, I use dynamic fields like *_s to store whole fields i want to facet / sort on, I use *_t for fields I want to have tokenized only by whitespace, and I use *_ft for fields I want to tokenize on whitespace and apply an english port stemmer to. With those dynamic field definitions I can send field names like sort_order_s, description_t, and description_ft  and have them handled properly without an explicit full definition for each field name.

- Donovan

To unsubscribe from this group, send email to php-solr-clie...@googlegroups.com.
回覆所有人
回覆作者
轉寄
0 則新訊息