You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by dharhsana <re...@gmail.com> on 2009/09/14 07:19:15 UTC

Issue on Facet field and exact match

Hi to all,

While i am working with facet using solrj, i am using string filed in schema
to avoid split in the word(i.e,Rekha dharshana, previously i was getting
rekha separate word and dharshana separate word..),in order to avoid this in
shema i use two fileds to index. My Schema.xml will look like this

<field name="userId" type="text" indexed="true" stored="true" />
<field name="blogId" type="text" indexed="true" stored="true" />
<field name="postId" type="text" indexed="true" stored="true" />
<field name="blogTitle" type="text" indexed="true" stored="true" />
<field name="postTitle" type="text" indexed="true" stored="true" />
<field name="postMessage" type="text" indexed="true" stored="true" />


<field name="blogTitle_exact" type="string" indexed="true" stored="false"/>
<field name="blogId_exact" type="string" indexed="true" stored="false"/>
<field name="userId_exact" type="string" indexed="true" stored="false"/>
<field name="postId_exact" type="string" indexed="true" stored="false" />
<field name="postTitle_exact" type="string" indexed="true" stored="false" />
<field name="postMessage_exact" type="string" indexed="true" stored="false"
/>

And this is my copy field..

<copyField source="blogTitle" dest="blogTitle_exact"/>
<copyField source="userId" dest="userId_exact"/>
<copyField source="blogId" dest="blogId_exact"/>
<copyField source="postId" dest="postId_exact"/>
<copyField source="postTitle" dest="postTitle_exact"/>
<copyField source="postMessage" dest="postMessage_exact"/>

This is my coding where i add fileds for blog details to solr,

 SolrInputDocument solrInputDocument = new SolrInputDocument();
 solrInputDocument.addField("blogTitle","$Never Fails$");
 solrInputDocument.addField("blogId","$Never Fails$");
 solrInputDocument.addField("userId",1);

This is my coding to add fileds for post details to solr..

solrInputDocument.addField("blogId","$Never Fails$");
solrInputDocument.addField("postId","$Never Fails post$");
solrInputDocument.addField("postTitle","$Never Fails post$");
solrInputDocument.addField("postMessage","$Never Fails post message$");

While i am quering it from solr, this is my coding..


 SolrQuery queryOfMyBlog = new SolrQuery("blogId_exact:Never Fails");
         queryOfMyBlog.setFacet(true);
         queryOfMyBlog.addFacetField("blogTitle_exact");
         queryOfMyBlog.addFacetField("userId_exact");
         queryOfMyBlog.addFacetField("blogId_exact");
         queryOfMyBlog.setFacetMinCount(1);
         queryOfMyBlog.setIncludeScore(true);

 List<FacetField> facets = query.getFacetFields();
           List listOfAllValues =  new ArrayList();
            System.out.println("inside facettt  size"+facets.size());
            for(FacetField facet : facets)
            {
                 System.out.println("inside for");
                List<FacetField.Count> facetEntries = facet.getValues();
                for(FacetField.Count fcount : facetEntries)
                {
                    String s= fcount.getName();
                    listOfAllValues.add(s);
                     System.out.println("BlogId"+s);
                }
            }


In the above code it copies the field from blogId,blogTitle,userId to
blogId_exact,blogTitle_exact,userId_exact,so that i can get the out put ,but
while i am indexing it to solr i index the filed in this manner ie.. "$Never
Fails$" this i do to get an exact search but i am not getting the exact
search ,when i try to query only "Never Fails" it also brings and show me
the "Success Never Fails" field to ..I need only to display Never Fails
details of the particular blog,but i even get "Success Never Fails" along
with that... what should i do for this to get exact match..

The above is my First Issue...

The next issue is ,when i am querying the post details , the same thing i do
,to get the post details...


SolrQuery queryOfMyPost = new SolrQuery("blogId_exact:$Success Never
Fails$");
             queryOfMyPost.setFacet(true);
             queryOfMyPost.addFacetField("blogId_exact");
             queryOfMyPost.addFacetField("postId_exact");
             queryOfMyPost.addFacetField("postTitle_exact");
             queryOfMyPost.addFacetField("postMessage_exact");
             queryOfMyPost.setFacetMinCount(1);
             queryOfMyPost.setIncludeScore(true);


List<FacetField> facetsForPost = queryPost.getFacetFields();
           List listOfAllFacetsForPost =  new ArrayList();
           System.out.println("inside facettt  size"+facetsForPost);
            for(FacetField facetPost1 : facetsForPost)
            {
                 System.out.println("inside for"+facetPost1);
                List<FacetField.Count> facetEntries =
facetPost1.getValues();
                for(FacetField.Count fcount1 : facetEntries)
                {
                    String s1= fcount1.getName();
                    listOfAllFacetsForPost.add(s1);
                     System.out.println("Post details"+ s1);
                }
            }

Here in the above facet filed postId_exact,postTitle_exact,postMessage_exact
i get null values..

the copy filed has not been copied to those values.. so i get null values
for this..


Please check my code and tell me where i am wrong...

And clear my issue on exact match...

Wailting for your reply..

Regards,

Rekha.


-- 
View this message in context: http://www.nabble.com/Issue-on-Facet-field-and-exact-match-tp25430457p25430457.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Issue on Facet field and exact match

Posted by Shalin Shekhar Mangar <sh...@gmail.com>.
On Mon, Sep 14, 2009 at 10:49 AM, dharhsana <re...@gmail.com>wrote:

>
>
> This is my coding where i add fileds for blog details to solr,
>
>  SolrInputDocument solrInputDocument = new SolrInputDocument();
>  solrInputDocument.addField("blogTitle","$Never Fails$");
>  solrInputDocument.addField("blogId","$Never Fails$");
>  solrInputDocument.addField("userId",1);
>
> This is my coding to add fileds for post details to solr..
>
> solrInputDocument.addField("blogId","$Never Fails$");
> solrInputDocument.addField("postId","$Never Fails post$");
> solrInputDocument.addField("postTitle","$Never Fails post$");
> solrInputDocument.addField("postMessage","$Never Fails post message$");
>
> While i am quering it from solr, this is my coding..
>
>
>  SolrQuery queryOfMyBlog = new SolrQuery("blogId_exact:Never Fails");
>         queryOfMyBlog.setFacet(true);
>         queryOfMyBlog.addFacetField("blogTitle_exact");
>         queryOfMyBlog.addFacetField("userId_exact");
>         queryOfMyBlog.addFacetField("blogId_exact");
>         queryOfMyBlog.setFacetMinCount(1);
>         queryOfMyBlog.setIncludeScore(true);
>
>
You are indexing "$Never Fails$" into the field so you should search for the
same. You don't need to add $ for exact searches on a string type field so
you can just index "Never Fails". Also, to make it a exact phrase search
enclose the query with quotes e.g. blogId_exact:"Never Fails"


-- 
Regards,
Shalin Shekhar Mangar.