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 "tomas.kalas" <ka...@email.cz> on 2015/01/09 12:47:30 UTC

Tokenizer or Filter ?

Hello, i have a question what i have to use tokenizer or filter ?
I need separate 2 chanels. I wrote this here earlier, but realize it with
solr basic tools it is not probably possible. And i',m trying to write own
tool for this task.
I have this input <d1>Hello</d1><d2>Hello</d2><d1>How are you ?</d1><d2>Fine
and you're?</d2> ....
d1 - direction1
d2 - direction2
and i want to output only d1 and between this result search some words, for
example output should be:
Output: [<d1>Hello</d1>,<d1>How are you?</d1><d1>....</d1>....] 

I wrote my idea in java, but i dont know where  to incorporate it. If to
Filter or Tokenizer and some advices how to start? I probably must extends
some lucene library and include it easily modificated there isn't it ?

Here is my code:

package test1;
import java.util.Arrays;

public class Test1 {


    public static void main(String[] args) {
        String dialogue = "<d1>Hello</d1><d2>Hello</d2><d1>How are you
?</d1><d2>Fine and you're?</d2> ....";

        String[] input = dialogue.split("(?<=</d[12]>)\\d*(?=<d[12]>)");

        int countD1 = 0;

        for (String input1 : input) {
            if (input1.startsWith("<d1>")) {
                countD1++;
            }
        }
        String [] d1 = new String[countD1];
        int array = 0;
        
        for (String input1 : input) {
            if (input1.startsWith("<d1>")) {
                d1[array] = input1;
                array++;
            }
        }
        String d1Out = Arrays.toString(d1);
        System.out.println(d1Out); 
//Return s1Out
         }
}

Thanks for you advices. 



--
View this message in context: http://lucene.472066.n3.nabble.com/Tokenizer-or-Filter-tp4178346.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Tokenizer or Filter ?

Posted by Jack Krupansky <ja...@gmail.com>.
It's what Java has, whatever that is:
http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html

So, maybe the correct answer is neither, but similar to both.

-- Jack Krupansky

On Wed, Jan 14, 2015 at 9:06 AM, tomas.kalas <ka...@email.cz> wrote:

> Oh yeah, that is it. Thank you very much for your patience. And a last
> question at the end what type regEx Solr actually using ? POSIX or PCRE ?
> Thanks.
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Tokenizer-or-Filter-tp4178346p4179505.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>

Re: Tokenizer or Filter ?

Posted by "tomas.kalas" <ka...@email.cz>.
Oh yeah, that is it. Thank you very much for your patience. And a last
question at the end what type regEx Solr actually using ? POSIX or PCRE ?
Thanks.



--
View this message in context: http://lucene.472066.n3.nabble.com/Tokenizer-or-Filter-tp4178346p4179505.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Tokenizer or Filter ?

Posted by Jack Krupansky <ja...@gmail.com>.
I was suspecting it might do that - the pattern is "greedy" and takes the
longest matching pattern. Add a question mark after the asterisk to use
stingy mode that matches the shortest pattern.

-- Jack Krupansky

On Wed, Jan 14, 2015 at 8:37 AM, tomas.kalas <ka...@email.cz> wrote:

> I just used Solr UI Analyzer for my test, or must i indexed it firstly?
>
> I used this XML code in my schema:
>
> <fieldType name="direction1" class="solr.TextField"
> positionIncrementGap="100">
>     <analyzer>
>       <charFilter class="solr.PatternReplaceCharFilterFactory"
>                   pattern="&lt;d1&gt;.*&lt;/d1&gt;" replacement=""/>
>       <tokenizer class="solr.KeywordTokenizerFactory"/>
>     </analyzer>
>   </fieldType>
>
> This is my result:
> <http://lucene.472066.n3.nabble.com/file/n4179496/dir1.png>
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Tokenizer-or-Filter-tp4178346p4179496.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>

Re: Tokenizer or Filter ?

Posted by "tomas.kalas" <ka...@email.cz>.
I just used Solr UI Analyzer for my test, or must i indexed it firstly?

I used this XML code in my schema: 

<fieldType name="direction1" class="solr.TextField"
positionIncrementGap="100">
    <analyzer>
      <charFilter class="solr.PatternReplaceCharFilterFactory"
                  pattern="&lt;d1&gt;.*&lt;/d1&gt;" replacement=""/>
      <tokenizer class="solr.KeywordTokenizerFactory"/>
    </analyzer>
  </fieldType>

This is my result:
<http://lucene.472066.n3.nabble.com/file/n4179496/dir1.png> 



--
View this message in context: http://lucene.472066.n3.nabble.com/Tokenizer-or-Filter-tp4178346p4179496.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Tokenizer or Filter ?

Posted by Jack Krupansky <ja...@gmail.com>.
It should replace all occurrences of the pattern. Post your specific filter
XML. Patterns can be very tricky.

Use the Solr Admin UI analysis page to see how the filtering is occurring.

-- Jack Krupansky

On Wed, Jan 14, 2015 at 7:16 AM, tomas.kalas <ka...@email.cz> wrote:

> Jack, thanks for help, but if i used PatternReplaceCharFilterFactory for
> example for this :
> <d1>text d1</d1><d2>text d2</d2><d1>text d1</d1><d2>text 2 ok</d2> then at
> output i only get segment <d2>text 2 ok</d2> when is <d2> text d2</d2>
> between marks <d1> .....</d1>.<d2>...</d2> <d1>...</d1>so the filter
> probably takes only first d1 and last d1 and if is something between it so
> the filter it don't skip it and replace it by space too, when i set at
> replacement space. So not better used the update processor ? If you are
> described it well in your book then i will buy it.
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Tokenizer-or-Filter-tp4178346p4179477.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>

Re: Tokenizer or Filter ?

Posted by "tomas.kalas" <ka...@email.cz>.
Jack, thanks for help, but if i used PatternReplaceCharFilterFactory for
example for this :
<d1>text d1</d1><d2>text d2</d2><d1>text d1</d1><d2>text 2 ok</d2> then at
output i only get segment <d2>text 2 ok</d2> when is <d2> text d2</d2>
between marks <d1> .....</d1>.<d2>...</d2> <d1>...</d1>so the filter
probably takes only first d1 and last d1 and if is something between it so
the filter it don't skip it and replace it by space too, when i set at
replacement space. So not better used the update processor ? If you are
described it well in your book then i will buy it.



--
View this message in context: http://lucene.472066.n3.nabble.com/Tokenizer-or-Filter-tp4178346p4179477.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Tokenizer or Filter ?

Posted by Jack Krupansky <ja...@gmail.com>.
Actually, you may be able to get by using PatternReplaceCharFilterFactory -
copy the source value to two fields, one that treats "<d2>.*</d2>" as the
delimiter pattern to delete and then other uses "<d1>.*</d1>" as the
delimiter pattern to delete, so the first field has only <d1> and then
second has only <d2>. You can use a second pattern char filter to remove
the "<[/]d[12>" markers as well, probably changing them to a space in both
cases.

See:
http://lucene.apache.org/core/4_10_3/analyzers-common/org/apache/lucene/analysis/pattern/PatternReplaceCharFilterFactory.html

-- Jack Krupansky

On Tue, Jan 13, 2015 at 11:40 AM, Jack Krupansky <ja...@gmail.com>
wrote:

> Would it be sufficient for your user case to simply extract all the <d1>
> into one field and all the <d2> in another field? If so, the update
> processor script would be very simple, simply matching all "<d1>.*</d1>"
> and copying them to a separate field value and same for <d2>.
>
> If you want examples of script update processors, see my Solr e-book:
>
> http://www.lulu.com/us/en/shop/jack-krupansky/solr-4x-deep-dive-early-access-release-7/ebook/product-21203548.html
>
> -- Jack Krupansky
>
> On Tue, Jan 13, 2015 at 9:21 AM, tomas.kalas <ka...@email.cz> wrote:
>
>> Thanks Jack for your advice. Can you please explain me little more, how it
>> works? From Apache Wiki it's not to clear for me. I can write some
>> javaScript code when i want filtering some data ? In this case i have
>> <d1>bla bla bla</d1> <d2> bla bla bla </d2> <d1>bla bla bla </d1> and i
>> want
>> filtering <d2> bla bla bla </d2>, But in other case i want filtering all
>> <d1> .... </d1> then i suppose i used it at indexed data and filtering
>> from
>> them? Thanks
>>
>>
>>
>> --
>> View this message in context:
>> http://lucene.472066.n3.nabble.com/Tokenizer-or-Filter-tp4178346p4179173.html
>> Sent from the Solr - User mailing list archive at Nabble.com.
>>
>
>

Re: Tokenizer or Filter ?

Posted by Jack Krupansky <ja...@gmail.com>.
Would it be sufficient for your user case to simply extract all the <d1>
into one field and all the <d2> in another field? If so, the update
processor script would be very simple, simply matching all "<d1>.*</d1>"
and copying them to a separate field value and same for <d2>.

If you want examples of script update processors, see my Solr e-book:
http://www.lulu.com/us/en/shop/jack-krupansky/solr-4x-deep-dive-early-access-release-7/ebook/product-21203548.html

-- Jack Krupansky

On Tue, Jan 13, 2015 at 9:21 AM, tomas.kalas <ka...@email.cz> wrote:

> Thanks Jack for your advice. Can you please explain me little more, how it
> works? From Apache Wiki it's not to clear for me. I can write some
> javaScript code when i want filtering some data ? In this case i have
> <d1>bla bla bla</d1> <d2> bla bla bla </d2> <d1>bla bla bla </d1> and i
> want
> filtering <d2> bla bla bla </d2>, But in other case i want filtering all
> <d1> .... </d1> then i suppose i used it at indexed data and filtering from
> them? Thanks
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Tokenizer-or-Filter-tp4178346p4179173.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>

Re: Tokenizer or Filter ?

Posted by "tomas.kalas" <ka...@email.cz>.
Thanks Jack for your advice. Can you please explain me little more, how it
works? From Apache Wiki it's not to clear for me. I can write some
javaScript code when i want filtering some data ? In this case i have
<d1>bla bla bla</d1> <d2> bla bla bla </d2> <d1>bla bla bla </d1> and i want
filtering <d2> bla bla bla </d2>, But in other case i want filtering all
<d1> .... </d1> then i suppose i used it at indexed data and filtering from
them? Thanks



--
View this message in context: http://lucene.472066.n3.nabble.com/Tokenizer-or-Filter-tp4178346p4179173.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Tokenizer or Filter ?

Posted by Jack Krupansky <ja...@gmail.com>.
Consider an update processor - it can take any input, break it up any way
you want, and then output multiple field values.

You can even us the stateless script update processor to write the logic in
JavaScript.

-- Jack Krupansky

On Fri, Jan 9, 2015 at 6:47 AM, tomas.kalas <ka...@email.cz> wrote:

> Hello, i have a question what i have to use tokenizer or filter ?
> I need separate 2 chanels. I wrote this here earlier, but realize it with
> solr basic tools it is not probably possible. And i',m trying to write own
> tool for this task.
> I have this input <d1>Hello</d1><d2>Hello</d2><d1>How are you
> ?</d1><d2>Fine
> and you're?</d2> ....
> d1 - direction1
> d2 - direction2
> and i want to output only d1 and between this result search some words, for
> example output should be:
> Output: [<d1>Hello</d1>,<d1>How are you?</d1><d1>....</d1>....]
>
> I wrote my idea in java, but i dont know where  to incorporate it. If to
> Filter or Tokenizer and some advices how to start? I probably must extends
> some lucene library and include it easily modificated there isn't it ?
>
> Here is my code:
>
> package test1;
> import java.util.Arrays;
>
> public class Test1 {
>
>
>     public static void main(String[] args) {
>         String dialogue = "<d1>Hello</d1><d2>Hello</d2><d1>How are you
> ?</d1><d2>Fine and you're?</d2> ....";
>
>         String[] input = dialogue.split("(?<=</d[12]>)\\d*(?=<d[12]>)");
>
>         int countD1 = 0;
>
>         for (String input1 : input) {
>             if (input1.startsWith("<d1>")) {
>                 countD1++;
>             }
>         }
>         String [] d1 = new String[countD1];
>         int array = 0;
>
>         for (String input1 : input) {
>             if (input1.startsWith("<d1>")) {
>                 d1[array] = input1;
>                 array++;
>             }
>         }
>         String d1Out = Arrays.toString(d1);
>         System.out.println(d1Out);
> //Return s1Out
>          }
> }
>
> Thanks for you advices.
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Tokenizer-or-Filter-tp4178346.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>

Re: Tokenizer or Filter ?

Posted by "tomas.kalas" <ka...@email.cz>.
I'm used the same regex and it doesn't work unfortunately. Or should I
somehow change the regex? Thanks.



--
View this message in context: http://lucene.472066.n3.nabble.com/Tokenizer-or-Filter-tp4178346p4178389.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Tokenizer or Filter ?

Posted by Ahmet Arslan <io...@yahoo.com.INVALID>.
Can't you use solr.PatternTokenizerFactory for this task?



On Friday, January 9, 2015 1:48 PM, tomas.kalas <ka...@email.cz> wrote:
Hello, i have a question what i have to use tokenizer or filter ?
I need separate 2 chanels. I wrote this here earlier, but realize it with
solr basic tools it is not probably possible. And i',m trying to write own
tool for this task.
I have this input <d1>Hello</d1><d2>Hello</d2><d1>How are you ?</d1><d2>Fine
and you're?</d2> ....
d1 - direction1
d2 - direction2
and i want to output only d1 and between this result search some words, for
example output should be:
Output: [<d1>Hello</d1>,<d1>How are you?</d1><d1>....</d1>....] 

I wrote my idea in java, but i dont know where  to incorporate it. If to
Filter or Tokenizer and some advices how to start? I probably must extends
some lucene library and include it easily modificated there isn't it ?

Here is my code:

package test1;
import java.util.Arrays;

public class Test1 {


    public static void main(String[] args) {
        String dialogue = "<d1>Hello</d1><d2>Hello</d2><d1>How are you
?</d1><d2>Fine and you're?</d2> ....";

        String[] input = dialogue.split("(?<=</d[12]>)\\d*(?=<d[12]>)");

        int countD1 = 0;

        for (String input1 : input) {
            if (input1.startsWith("<d1>")) {
                countD1++;
            }
        }
        String [] d1 = new String[countD1];
        int array = 0;
        
        for (String input1 : input) {
            if (input1.startsWith("<d1>")) {
                d1[array] = input1;
                array++;
            }
        }
        String d1Out = Arrays.toString(d1);
        System.out.println(d1Out); 
//Return s1Out
         }
}

Thanks for you advices. 



--
View this message in context: http://lucene.472066.n3.nabble.com/Tokenizer-or-Filter-tp4178346.html
Sent from the Solr - User mailing list archive at Nabble.com.