You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@lenya.apache.org by Michael Wechner <mi...@wyona.com> on 2007/07/01 22:21:52 UTC

Re: API for searching contents

Chokchai Phatharamalai wrote:

> Greetings,
>
> I'm trying to write a Java class which invoke Lenya to search contents 
> in a publication, but I failed. The problem is I couldn't find an API 
> for searching the contents. At the very beginning, I expected to see 
> some class which contains search API like below.


what Lenya version are you refering to?

Cheers

Michael

>
> [code]
>   public List<SearchResult> search ( String keyword ) {
>        // finding the contents and return a List of SearchResult 
> instances.
>   }
> [/code]
>
> But I couldn't find in any package. :(
> Is there any documents I've missed? Any suggestion would be most 
> appreciated.
>
> Thank you in advance.
> Chokchai Phatharamalai
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@lenya.apache.org
> For additional commands, e-mail: user-help@lenya.apache.org
>
>


-- 
Michael Wechner
Wyona      -   Open Source Content Management - Yanel, Yulup
http://www.wyona.com
michael.wechner@wyona.com, michi@apache.org
+41 44 272 91 61


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@lenya.apache.org
For additional commands, e-mail: user-help@lenya.apache.org


Re: API for searching contents

Posted by Chokchai Phatharamalai <ju...@gmail.com>.
Bob Harner wrote:
> On 7/1/07, Michael Wechner <mi...@wyona.com> wrote:
>> Chokchai Phatharamalai wrote:
>>
>> > Greetings,
>> >
>> > I'm trying to write a Java class which invoke Lenya to search contents
>> > in a publication, but I failed. The problem is I couldn't find an API
>> > for searching the contents. At the very beginning, I expected to see
>> > some class which contains search API like below.
>>
>>
>> what Lenya version are you refering to?
>>
>> Cheers
>>
>> Michael
>>
>> >
>> > [code]
>> >   public List<SearchResult> search ( String keyword ) {
>> >        // finding the contents and return a List of SearchResult
>> > instances.
>> >   }
>> > [/code]
>> >
>> > But I couldn't find in any package. :(
>> > Is there any documents I've missed? Any suggestion would be most
>> > appreciated.
>> >
>> > Thank you in advance.
>> > Chokchai Phatharamalai
>
> I suppose you're probably asking about Lenya 1.2, but for the
> not-quite-released 1.4 version there is the Lucene module's API --
> http://lenya.apache.org/apidocs/1.4/modules/lucene/ The Lucene module
> implements the Searcher interface via AbstractSearcher.java and
> DefaultSearcherImpl.java
Dear Lenya team,
    First of all, thank you very much for your kind responses. As Bob 
mentioned, I was be able to use Search API in Lenya 1.4 via class 
DefaultSearcherImpl. The snippet below is sample of my code.

[code]
            DefaultSearcherImpl searcher = new DefaultSearcherImpl( );
            FSDirectory directory = FSDirectory.getDirectory( 
INDEX_FILE_PATH , false );
            searcher.addDirectory( directory );
            PhraseQuery query = new PhraseQuery( );
            Term term = new Term( "body", query_string );
            query.add( term );
            Hits hits = searcher.search( query );
            for(int i = 0 ; i < hits.length( ) ; i++ ) {
                Document doc = hits.doc( i );
                Enumeration en = doc.fields();
                String buf = "";
                while( en.hasMoreElements( ) ) {
                    Field field = ( Field )en.nextElement( );
                    buf += "key:" + field.name( ) + "=" + doc.get( 
field.name( ) ) + "\n";
                }
                System.out.println( buf );
          }
[/code]

    In brief, I query documents via PhraseQuery instance. Then I get 
hits as results of my query. From Hits, I could get the documents from 
it. The document here is instance of class 
org.apache.lucene.document.Document which contains uuid field. The 
problem is I tried to get the url of each document without success. :'(
    I looked into Core Modules->linking API and Standard Modules->lucene 
API. I believe that I could get the url from 
org.apache.lenya.cms.publication.Document but I couldn't find a way to 
turn org.apache.lucene.document.Document to 
org.apache.lenya.cms.publication.Document. Does I miss a thing? Is there 
any clue of resource which I should refer to?

Ps.
- Feel free to use my snippet in your document if you wish. It would be 
most appreciated if I could help any. :)
- Thank you in advance ;)

Best regards,
Chokchai Phatharamalai



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@lenya.apache.org
For additional commands, e-mail: user-help@lenya.apache.org


Re: API for searching contents

Posted by Bob Harner <bo...@gmail.com>.
On 7/1/07, Michael Wechner <mi...@wyona.com> wrote:
> Chokchai Phatharamalai wrote:
>
> > Greetings,
> >
> > I'm trying to write a Java class which invoke Lenya to search contents
> > in a publication, but I failed. The problem is I couldn't find an API
> > for searching the contents. At the very beginning, I expected to see
> > some class which contains search API like below.
>
>
> what Lenya version are you refering to?
>
> Cheers
>
> Michael
>
> >
> > [code]
> >   public List<SearchResult> search ( String keyword ) {
> >        // finding the contents and return a List of SearchResult
> > instances.
> >   }
> > [/code]
> >
> > But I couldn't find in any package. :(
> > Is there any documents I've missed? Any suggestion would be most
> > appreciated.
> >
> > Thank you in advance.
> > Chokchai Phatharamalai

I suppose you're probably asking about Lenya 1.2, but for the
not-quite-released 1.4 version there is the Lucene module's API --
http://lenya.apache.org/apidocs/1.4/modules/lucene/ The Lucene module
implements the Searcher interface via AbstractSearcher.java and
DefaultSearcherImpl.java

For 1.2.5 I see
http://svn.apache.org/repos/asf/lenya/tags/RELEASE_1_2_5/src/java/org/apache/lenya/lucene/SearchFiles.java
although I am not at all familar with that code.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@lenya.apache.org
For additional commands, e-mail: user-help@lenya.apache.org