lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rahul.sawh...@philips.com
Subject How to search/index in a generic way? - Urgent!
Date Sat, 13 Oct 2001 13:22:54 GMT
Hi all,
I am using lucene for indexing and then searching for files available on a LAN.
I am not indexing the contents of the files as i just want to search on the bases
of file names.

Now, i would like to know, how to modify the code below so that i can search in
a generic way.

In short, i want to handle the following use cases:

Input->
my image
Output->
myimage1.gif
myimage2.gif
my image3.gif

Currently, the query returns me this result only if i give myimage (without the space) as
the input.

Another use case:
Input->
business com
Output->
business comunication.doc

Currently, the query returns me this result only if i give business comunication
[or business (or communication)  ] as the input.


Any suggestions are most welcome :-)
--------------------------------------------------------------

Index:
-----------------> Regarding this method, which analyzer would be appropriate for creating
the writer?
    private void indexDocs(IndexWriter writer, File file) throws Exception
    {
        Document doc = new Document();
        doc.add(Field.Text("path",file.getPath()));
        doc.add(Field.Text("name",file.getName()));
        doc.add(Field.Keyword("modified",DateField.timeToString(file.lastModified())));
        writer.addDocument(doc);

        if (file.isDirectory()) {
            String[] files = file.list();
            for (int i = 0; i < files.length; i++) {
                indexDocs(writer, new File(file, files[i]));
            }
        }
    }


Search:
----------------------> Should the analyzer use here be same as the one used for creating
indexes?
----------------------> Which analyzer is appropriate here?
----------------------> What type of Query Class is appropriate? I have used PhraseQuery.
----------------------> setSlop does not seem to have any effect on results.

    private void searchShares(OutputStream out, String queryStr)
        throws java.io.IOException, com.lucene.queryParser.ParseException
    {
            queryStr.trim();
            if (queryStr.length() == -1) {
                out.println("No query!");
                out.flush();
                return;
            }
            IndexSearcher searcher = new IndexSearcher("D:\\Searchindex");
            Analyzer analyzer = new StandardAnalyzer();

            PhraseQuery query = new PhraseQuery();
            StringTokenizer tokens = new StringTokenizer(queryStr, " ") ;
            while ( tokens.hasMoreTokens() ) {
                String token = tokens.nextToken();
                query.add(new Term("name",token));
            }
            query.setSlop(10);

            Hits hits = searcher.search(query);
            out.println(hits.length() + " total matching document(s) found!");
            for (int i = 0; i < hits.length(); i++) {
                out.println(hits.doc(i).get("name"));
                out.flush();
            }
            searcher.close();
    }

----------------------------------------------------------------

Can anyone also point out some links where one can get more information regarding development
using lucene (other than mailing list archives and java docs)???

Thanks for any help!

==Rahul==
-------------------------------------------
rahul.sawhney@philips.com
Ph: 5579000 Extn: 1029
-------------------------------------------



Mime
View raw message