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 RE: MultiFieldQueryParser question
Date Fri, 08 Feb 2008 17:42:40 GMT
Solved it, for those who were wondering where I went wrong....

I've built up an ArrayList while adding my attributes to a lucence doc
and updated my multiquerySearchParser to contain all these attribute
names as follows

Object[] attributeNamesArray = (Object[]) attrList.toArray();
        String[] otherFieldsArray  = {IDENTITY, NAME};
        String[] searchFields = new String[attributeNamesArray.length +
otherFieldsArray.length];        
        
        System.arraycopy(attributeNamesArray, 0, searchFields, 0,
attributeNamesArray.length);
        System.arraycopy(otherFieldsArray, 0, searchFields,
attributeNamesArray.length, otherFieldsArray.length);
      
        MultiFieldQueryParser multiparser = new
MultiFieldQueryParser(searchFields, new StandardAnalyzer());
	  multiparser.setDefaultOperator(QueryParser.Operator.OR); 
        Query query = multiparser.parse("aaa*");


When I call toString() on my query, the syntax looks correct

Query guid:aaa* name:aaa* value:aaa* id:aaa* name:aaa* 

When I debug into the hits documents, I can see that only the 2 id
results are returned.
Its not finding the guid as a hit because its in the same document as
the id.
I discovered this by using Luke to inspect the documents.



-----Original Message-----
From: Mitchell, Erica [mailto:Erica.Mitchell@iona.com] 
Sent: 08 February 2008 14:54
To: java-user@lucene.apache.org
Subject: MultiFieldQueryParser question

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

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