You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by "Mitchell, Erica" <Er...@iona.com> on 2008/02/08 15:53:37 UTC

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


Re: MultiFieldQueryParser question

Posted by Chris Hostetter <ho...@fucit.org>.
: Subject: MultiFieldQueryParser question
: Date: Fri, 8 Feb 2008 14:53:37 -0000
: Message-ID:
:     <E9...@emea-ems1.IONAGLOBAL.COM>
: In-Reply-To: <35...@mail.gmail.com>

http://people.apache.org/~hossman/#threadhijack

Thread Hijacking on Mailing Lists

When starting a new discussion on a mailing list, please do not reply to 
an existing message, instead start a fresh email.  Even if you change the 
subject line of your email, other mail headers still track which thread 
you replied to and your question is "hidden" in that thread and gets less 
attention.   It makes following discussions in the mailing list archives 
particularly difficult.
See Also:  http://en.wikipedia.org/wiki/Thread_hijacking




-Hoss


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


RE: MultiFieldQueryParser question

Posted by "Mitchell, Erica" <Er...@iona.com>.
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