lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <erlend.bjo...@aftenposten.no>
Subject SV: Search in multi fields with cross field AND ?
Date Thu, 04 Aug 2005 11:47:50 GMT
Hi there Martin!

>try this code:
>QueryParser q = new QueryParser("text", analyzer); 

What is "text" in this context ? All fields for the Field.text ?
Or like I understand it, name of a field, like my "keywords1" ??

Anyway, this code didn't work at all with "text" at least, 0 hits,
Even with one word....  When I e.g. put "keywords1" instead ... 
it worked for this field of course.

Not sure if you understood my question ? :-) 

---

I create the index like this, I guess I can't prepare the index for
my multi field, cross field AND search in some way ?

        IndexWriter writer = new IndexWriter(ramDir, getAnalyzer(), true);
        List companies = retrieveCompanies();

        for(int i=0;i < companies.size(); i++) {

            CompanyBean bean = (CompanyBean) companies.get(i);

            Document doc = new Document();
            doc.add(Field.Keyword("companyId", "" + bean.getCompanyId()));

            if(bean.getCompanyName() != null){
                doc.add(Field.Text("companyName", bean.getCompanyName()));
		}
		if(bean.getKeywords1() != null) {
                Field f = Field.Text("keywords1", bean.getKeywords1());
                f.setBoost(3.0f);
                doc.add(f);
            }
            if(bean.getKeywords2() != null) {
                Field f = Field.Text("keywords2", bean.getKeywords2());
                doc.add(f);
            }

            writer.addDocument(doc, getAnalyzer());
        }

        int noDocs = writer.docCount();

        writer.optimize();
        writer.close();

---

    public Analyzer getAnalyzer() {
        Analyzer analyzer = new StandardAnalyzer();
        return analyzer;
    }

---


Cheers,
Erlend

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


Mime
View raw message