Bob Harner wrote:
On 7/1/07, Michael Wechner <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to