You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by rachun <ra...@gmail.com> on 2014/01/10 10:06:05 UTC

How to index data in muliValue field with key

*This might be very simple question but I can't figure out after i tried to
google all day.

I just want the data to show like this*

/"record": [
    {
       id: "product001"
       name: "iPhone case",
      title: {
          th: "เคส ไอโฟน5 iphone5 Case วิบวับ ลายผสมมุกสีชมพู back case",
          en: "iphone5 Case pinky pearl back case"
   }
]/

*and this is my schema.xml*

/<field name="title" type="text_th" indexed="true" stored="true"
multiValued="true"/>
/

*this is my php code*

<?php

require_once( 'SolrPhpClient/Apache/Solr/Service.php' );
		$solr = new Apache_Solr_Service( 'localhost', '8983', './solr' );
		
		if( !$solr->ping() ) {
		  echo "Solr service is not responding";
		  exit;
		}

        $parts = array(
	    'spark_plug' => array(
	      'id' => 11,
	      'name' => 'Spark plug',
	      'title' => array(
		'th' => 'เคส sdsdไอโฟน4 iphone4 Case วิบวับ ลายหอไอเฟลสุดเก๋ สีชมพูเข้ม
ปปback case',
    		'en' => 'New design Iphone 4 case with pink and beutiful back case '
		   ),
	      'model' => array( 'a'=>'Boxster', 'b'=>'924' ),
	      'price' => 25.00,
	      'inStock' => true,
	    ),
	    'windshield' => array(
	      'id' => 2,
	      'name' => 'Windshield',
	      'model' => '911',
	      'price' => 15.50,
	      'inStock' => false,
	      'url'=>'http://store.weloveshopping.com/joeishiablex12'
	    )
	  	);

$documents = array();
	  
	  foreach ( $parts as $item => $fields ) {
	     $doc = new Apache_Solr_Document();
	    
	    foreach ( $fields as $key => $value ) {
	      if ( is_array( $value ) ) {
	        foreach ( $value as $datum ) {
	          $doc->setMultiValue( $key, $datum );
	        }
	      }
	      else {
	        $doc->$key = $value;
	      }
	    }
	    
	    $documents[] = $doc;
	  }

		try
			{
				$solr->addDocuments($documents);
				$solr->commit();
				$solr->optimize();
			}
		catch(Exeption $e)
			{
				echo $e->getMessage();
			}

?>

*but the response that I'm getting now like below as you see it has no key (
th or en) in response*

/"record": [
    {
       id: "product001"
       name: "iPhone case",
      title: {
           "เคส ไอโฟน5 iphone5 Case วิบวับ ลายผสมมุกสีชมพู back case",
           "iphone5 Case pinky pearl back case"
   }
]/


*Please help, million thanks 
Chun.*



--
View this message in context: http://lucene.472066.n3.nabble.com/How-to-index-data-in-muliValue-field-with-key-tp4110653.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: How to index data in muliValue field with key

Posted by rachun <ra...@gmail.com>.
thank you Mr. Steve. Now I understood and i figured out to separate field to
title_th and title_en and it worked ;)



--
View this message in context: http://lucene.472066.n3.nabble.com/How-to-index-data-in-muliValue-field-with-key-tp4110653p4110981.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: How to index data in muliValue field with key

Posted by Stefan Matheis <ma...@gmail.com>.
Doesn't work like that - a multivalued field is like a list. PHP doesn't make a difference between a list and a map - but Solr does. you can't have a key in those fields.  

But based on what infos you've provided .. it looks more like you do in fact need different analyzers to get the english vs. the thai text properly. You could try title_th and title_en and configure those fields according to your needs.

-Stefan  


On Friday, January 10, 2014 at 10:06 AM, rachun wrote:

> *This might be very simple question but I can't figure out after i tried to
> google all day.
>  
> I just want the data to show like this*
>  
> /"record": [
> {
> id: "product001"
> name: "iPhone case",
> title: {
> th: "เคส ไอโฟน5 iphone5 Case วิบวับ ลายผสมมุกสีชมพู back case",
> en: "iphone5 Case pinky pearl back case"
> }
> ]/
>  
> *and this is my schema.xml*
>  
> /<field name="title" type="text_th" indexed="true" stored="true"
> multiValued="true"/>
> /
>  
> *this is my php code*
>  
> <?php
>  
> require_once( 'SolrPhpClient/Apache/Solr/Service.php' );
> $solr = new Apache_Solr_Service( 'localhost', '8983', './solr' );
>  
> if( !$solr->ping() ) {
> echo "Solr service is not responding";
> exit;
> }
>  
> $parts = array(
> 'spark_plug' => array(
> 'id' => 11,
> 'name' => 'Spark plug',
> 'title' => array(
> 'th' => 'เคส sdsdไอโฟน4 iphone4 Case วิบวับ ลายหอไอเฟลสุดเก๋ สีชมพูเข้ม
> ปปback case',
> 'en' => 'New design Iphone 4 case with pink and beutiful back case '
> ),
> 'model' => array( 'a'=>'Boxster', 'b'=>'924' ),
> 'price' => 25.00,
> 'inStock' => true,
> ),
> 'windshield' => array(
> 'id' => 2,
> 'name' => 'Windshield',
> 'model' => '911',
> 'price' => 15.50,
> 'inStock' => false,
> 'url'=>'http://store.weloveshopping.com/joeishiablex12'
> )
> );
>  
> $documents = array();
>  
> foreach ( $parts as $item => $fields ) {
> $doc = new Apache_Solr_Document();
>  
> foreach ( $fields as $key => $value ) {
> if ( is_array( $value ) ) {
> foreach ( $value as $datum ) {
> $doc->setMultiValue( $key, $datum );
> }
> }
> else {
> $doc->$key = $value;
> }
> }
>  
> $documents[] = $doc;
> }
>  
> try
> {
> $solr->addDocuments($documents);
> $solr->commit();
> $solr->optimize();
> }
> catch(Exeption $e)
> {
> echo $e->getMessage();
> }
>  
> ?>
>  
> *but the response that I'm getting now like below as you see it has no key (
> th or en) in response*
>  
> /"record": [
> {
> id: "product001"
> name: "iPhone case",
> title: {
> "เคส ไอโฟน5 iphone5 Case วิบวับ ลายผสมมุกสีชมพู back case",
> "iphone5 Case pinky pearl back case"
> }
> ]/
>  
>  
> *Please help, million thanks  
> Chun.*
>  
>  
>  
> --
> View this message in context: http://lucene.472066.n3.nabble.com/How-to-index-data-in-muliValue-field-with-key-tp4110653.html
> Sent from the Solr - User mailing list archive at Nabble.com (http://Nabble.com).
>  
>