lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mitchell, Erica" <Erica.Mitch...@iona.com>
Subject MultiFieldQueryParser question
Date Fri, 08 Feb 2008 14:53:37 GMT
Hi,


I'm trying to build up an index of fields to represent an
org.eclipse.emf.ecore.EObject;


So I'm adding these fields to my lucene doc

doc.add(new Field(NAME, cls.getName(), Field.Store.YES,
Field.Index.TOKENIZED));
doc.add(new Field(IDENTITY, obj.eGet(cls.getEIDAttribute()).toString(),
Field.Store.YES, Field.Index.TOKENIZED));

I then get the Eattributes from my Eobject and I want to add these to
the index

 for (Object o : cls.getEAllAttributes()) {
            if (o instanceof EAttribute) {
                EAttribute attribute = (EAttribute) o;
                String attributeName = attribute.getName();
       	    Strung attributeValue = obj.eGet(attribute).toString();

		    doc.add(new Field(attributeName , attributeValue ,
Field.Store.YES, Field.Index.TOKENIZED));
		}
 }


This is how I'm searching all fields for text containing "aaa"

        String[] searchFields = {IDENTITY, NAME, ATTRIBUTE}; 
            
        MultiFieldQueryParser multiparser = new
MultiFieldQueryParser(searchFields, new StandardAnalyzer()); 
        multiparser.setDefaultOperator(QueryParser.Operator.OR); 
        Query query = multiparser.parse("aaa*");
        Hits hits = isearcher.search(query);


So using Luke I can see my index contains information like this

<id> aaa2
<id> aaa1

<guid> aaa2
<guid> pi4

<name> attribute
<name> poliyinstance


I'd like my query to return both the id fields and the guids.
The problem is the guid is added to the index by virtue of my
doc.addField(attributeName, attributeValue ...) 

So for the query to return the attributes correctly, I'd need to pass in
the attributeName which I don't have.

Is the answer simply that I should be keeping an array of the
attributeName's returned, and passing these as part of the String[] into
searchFields?

Thanks a million,
Erica

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

---------------------------------------------------------------------
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