You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by west suhanic <we...@gmail.com> on 2014/06/22 05:34:40 UTC

A question about FacetField constructor

Hello All:

I am building sample code using lucene v4.8.1 to explore
the new facet API. The problem I am having is that if I pass
a populated string array nothing gets indexed while if
I pass only the first element of the string array that value gets indexed.
The code found below shows the case that works and the case that does not
work. What am I doing wrong?

****************Start of code sample*************************

void showStuff( String... va )
{
              /** This code permits out the contents of va successfully.**/
              for( int ii = 0 ; ii < va.length ; ii++ )
                      System.out.println( "value[" + ii + "] " + va[ii] );
}

                for( final Map< String, String[] > fd : allFacetData )
                {

                        final Document doc = new Document();
                        for( final Map.Entry< String, String[] > entry :
fd.entrySet() )
                        {
                                final String key = entry.getKey();
                                String[] value = entry.getValue();
                                showStuff( value );

                                /**  This call indexes successfully **/
                                final FacetField newFF = new FacetField(
key, value[0] );

                                /**
                                   * This call will not index anything if
the value String array
                                   * has more than one element.
                                   *final FacetField newFF = new
FacetField( key, value );
                                   */
                                doc.add( newFF );
                        }

                        try
                        {
                                final Document theBuildDoc =
configFacetsHandle.
build( taxoWriter, doc );
                                indexWriter.addDocument( theBuildDoc );
                                indexWriter.addDocument(
configFacetsHandle.buil
d( taxoWriter, doc ) );
                        }
                        catch( IOException ioe )
                        {
                                eMsg.append( method );
                                eMsg.append(  " failed with the exception "
);
                                eMsg.append( ioe.toString() );
                                return constantValuesInterface.FAILURE;
                        }
                }

*******************End of code sample***************

regards,

West Suhanic

Re: A question about FacetField constructor

Posted by Shai Erera <se...@gmail.com>.
Reply wasn't sent to the list.
On Jun 22, 2014 8:15 PM, "Shai Erera" <se...@gmail.com> wrote:

> Can you post an example which demonstrates the problem? It's also
> interesting how you count the facets, eg do you use a TaxonomyFacets object
> or something else?
>
> Have you looked at the facet demo code? It contains examples for using
> hierarchical facets.
>
> Shai
> On Jun 22, 2014 8:08 PM, "west suhanic" <we...@gmail.com> wrote:
>
>> Hello:
>>
>> >What do you mean by does not index anything?
>>
>> When I do a search the value returned for the "dim" set to "Publish Date"
>> is null. If I pass through value[0] the publish date year is returned by
>> the search.
>>
>> setHierarchical was called.
>>
>> When a String[] with more than one element is passed an exception is not
>> thrown.
>>
>> I am open to all suggestions as to what I am missing.
>>
>> regards,
>>
>> west suhanic
>>
>>
>> On Sun, Jun 22, 2014 at 3:23 AM, Shai Erera <se...@gmail.com> wrote:
>>
>>> What do you mean by does not index anything? Do you get an exception
>>> when you add a String[] with more than one element?
>>>
>>> You should probably call conf.setHierarchical(dimension), but if you
>>> don't do that you should receive an IllegalArgumentException telling you to
>>> do that...
>>>
>>> Shai
>>>
>>>
>>> On Sun, Jun 22, 2014 at 6:34 AM, west suhanic <we...@gmail.com>
>>> wrote:
>>>
>>>> Hello All:
>>>>
>>>> I am building sample code using lucene v4.8.1 to explore
>>>> the new facet API. The problem I am having is that if I pass
>>>> a populated string array nothing gets indexed while if
>>>> I pass only the first element of the string array that value gets
>>>> indexed.
>>>> The code found below shows the case that works and the case that does
>>>> not
>>>> work. What am I doing wrong?
>>>>
>>>> ****************Start of code sample*************************
>>>>
>>>> void showStuff( String... va )
>>>> {
>>>>               /** This code permits out the contents of va
>>>> successfully.**/
>>>>               for( int ii = 0 ; ii < va.length ; ii++ )
>>>>                       System.out.println( "value[" + ii + "] " + va[ii]
>>>> );
>>>> }
>>>>
>>>>                 for( final Map< String, String[] > fd : allFacetData )
>>>>                 {
>>>>
>>>>                         final Document doc = new Document();
>>>>                         for( final Map.Entry< String, String[] > entry :
>>>> fd.entrySet() )
>>>>                         {
>>>>                                 final String key = entry.getKey();
>>>>                                 String[] value = entry.getValue();
>>>>                                 showStuff( value );
>>>>
>>>>                                 /**  This call indexes successfully **/
>>>>                                 final FacetField newFF = new FacetField(
>>>> key, value[0] );
>>>>
>>>>                                 /**
>>>>                                    * This call will not index anything
>>>> if
>>>> the value String array
>>>>                                    * has more than one element.
>>>>                                    *final FacetField newFF = new
>>>> FacetField( key, value );
>>>>                                    */
>>>>                                 doc.add( newFF );
>>>>                         }
>>>>
>>>>                         try
>>>>                         {
>>>>                                 final Document theBuildDoc =
>>>> configFacetsHandle.
>>>> build( taxoWriter, doc );
>>>>                                 indexWriter.addDocument( theBuildDoc );
>>>>                                 indexWriter.addDocument(
>>>> configFacetsHandle.buil
>>>> d( taxoWriter, doc ) );
>>>>                         }
>>>>                         catch( IOException ioe )
>>>>                         {
>>>>                                 eMsg.append( method );
>>>>                                 eMsg.append(  " failed with the
>>>> exception "
>>>> );
>>>>                                 eMsg.append( ioe.toString() );
>>>>                                 return constantValuesInterface.FAILURE;
>>>>                         }
>>>>                 }
>>>>
>>>> *******************End of code sample***************
>>>>
>>>> regards,
>>>>
>>>> West Suhanic
>>>>
>>>
>>>
>>

Re: A question about FacetField constructor

Posted by west suhanic <we...@gmail.com>.
Hello:

>What do you mean by does not index anything?

When I do a search the value returned for the "dim" set to "Publish Date"
is null. If I pass through value[0] the publish date year is returned by
the search.

setHierarchical was called.

When a String[] with more than one element is passed an exception is not
thrown.

I am open to all suggestions as to what I am missing.

regards,

west suhanic


On Sun, Jun 22, 2014 at 3:23 AM, Shai Erera <se...@gmail.com> wrote:

> What do you mean by does not index anything? Do you get an exception when
> you add a String[] with more than one element?
>
> You should probably call conf.setHierarchical(dimension), but if you don't
> do that you should receive an IllegalArgumentException telling you to do
> that...
>
> Shai
>
>
> On Sun, Jun 22, 2014 at 6:34 AM, west suhanic <we...@gmail.com>
> wrote:
>
>> Hello All:
>>
>> I am building sample code using lucene v4.8.1 to explore
>> the new facet API. The problem I am having is that if I pass
>> a populated string array nothing gets indexed while if
>> I pass only the first element of the string array that value gets indexed.
>> The code found below shows the case that works and the case that does not
>> work. What am I doing wrong?
>>
>> ****************Start of code sample*************************
>>
>> void showStuff( String... va )
>> {
>>               /** This code permits out the contents of va
>> successfully.**/
>>               for( int ii = 0 ; ii < va.length ; ii++ )
>>                       System.out.println( "value[" + ii + "] " + va[ii] );
>> }
>>
>>                 for( final Map< String, String[] > fd : allFacetData )
>>                 {
>>
>>                         final Document doc = new Document();
>>                         for( final Map.Entry< String, String[] > entry :
>> fd.entrySet() )
>>                         {
>>                                 final String key = entry.getKey();
>>                                 String[] value = entry.getValue();
>>                                 showStuff( value );
>>
>>                                 /**  This call indexes successfully **/
>>                                 final FacetField newFF = new FacetField(
>> key, value[0] );
>>
>>                                 /**
>>                                    * This call will not index anything if
>> the value String array
>>                                    * has more than one element.
>>                                    *final FacetField newFF = new
>> FacetField( key, value );
>>                                    */
>>                                 doc.add( newFF );
>>                         }
>>
>>                         try
>>                         {
>>                                 final Document theBuildDoc =
>> configFacetsHandle.
>> build( taxoWriter, doc );
>>                                 indexWriter.addDocument( theBuildDoc );
>>                                 indexWriter.addDocument(
>> configFacetsHandle.buil
>> d( taxoWriter, doc ) );
>>                         }
>>                         catch( IOException ioe )
>>                         {
>>                                 eMsg.append( method );
>>                                 eMsg.append(  " failed with the exception
>> "
>> );
>>                                 eMsg.append( ioe.toString() );
>>                                 return constantValuesInterface.FAILURE;
>>                         }
>>                 }
>>
>> *******************End of code sample***************
>>
>> regards,
>>
>> West Suhanic
>>
>
>

Re: A question about FacetField constructor

Posted by Shai Erera <se...@gmail.com>.
What do you mean by does not index anything? Do you get an exception when
you add a String[] with more than one element?

You should probably call conf.setHierarchical(dimension), but if you don't
do that you should receive an IllegalArgumentException telling you to do
that...

Shai


On Sun, Jun 22, 2014 at 6:34 AM, west suhanic <we...@gmail.com>
wrote:

> Hello All:
>
> I am building sample code using lucene v4.8.1 to explore
> the new facet API. The problem I am having is that if I pass
> a populated string array nothing gets indexed while if
> I pass only the first element of the string array that value gets indexed.
> The code found below shows the case that works and the case that does not
> work. What am I doing wrong?
>
> ****************Start of code sample*************************
>
> void showStuff( String... va )
> {
>               /** This code permits out the contents of va successfully.**/
>               for( int ii = 0 ; ii < va.length ; ii++ )
>                       System.out.println( "value[" + ii + "] " + va[ii] );
> }
>
>                 for( final Map< String, String[] > fd : allFacetData )
>                 {
>
>                         final Document doc = new Document();
>                         for( final Map.Entry< String, String[] > entry :
> fd.entrySet() )
>                         {
>                                 final String key = entry.getKey();
>                                 String[] value = entry.getValue();
>                                 showStuff( value );
>
>                                 /**  This call indexes successfully **/
>                                 final FacetField newFF = new FacetField(
> key, value[0] );
>
>                                 /**
>                                    * This call will not index anything if
> the value String array
>                                    * has more than one element.
>                                    *final FacetField newFF = new
> FacetField( key, value );
>                                    */
>                                 doc.add( newFF );
>                         }
>
>                         try
>                         {
>                                 final Document theBuildDoc =
> configFacetsHandle.
> build( taxoWriter, doc );
>                                 indexWriter.addDocument( theBuildDoc );
>                                 indexWriter.addDocument(
> configFacetsHandle.buil
> d( taxoWriter, doc ) );
>                         }
>                         catch( IOException ioe )
>                         {
>                                 eMsg.append( method );
>                                 eMsg.append(  " failed with the exception "
> );
>                                 eMsg.append( ioe.toString() );
>                                 return constantValuesInterface.FAILURE;
>                         }
>                 }
>
> *******************End of code sample***************
>
> regards,
>
> West Suhanic
>