You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@lucenenet.apache.org by Trevor Watson <tw...@datassimilate.com> on 2011/11/10 17:51:53 UTC

[Lucene.Net] Excluding search results

We'd like to have the ability to exclude items from a search given the 
ID (the ID is a link between a database for frequently updated 
information and the index for searching).

Optimally, it'd be great if we could just run the query vs the index AND 
the database, but I haven't found anything for doing that (using SQLite).

Would this be a custom Filter?  I've dealt with custom analyzers in the 
past, but that wouldn't be useful here.  Is there an existing filter 
where we can say "ignore these documents?"

Thanks in advance.

Trevor Watson

RE: [Lucene.Net] Excluding search results

Posted by Digy <di...@gmail.com>.
You can use QueryWrapperFilter to exclude some documents from the result set
such as

Filter filter = new QueryWrapperFilter(new QueryParser("ID",
analyzer).Parse("sampleid"));
or
Filter filter = new QueryWrapperFilter(new TermQuery(new
Term("ID","sampleid")));

depending on ID field is indexed as "analyzed" or not.

DIGY

-----Original Message-----
From: Trevor Watson [mailto:twatson@datassimilate.com] 
Sent: Thursday, November 10, 2011 6:52 PM
To: lucene-net-user@lucene.apache.org
Subject: [Lucene.Net] Excluding search results

We'd like to have the ability to exclude items from a search given the 
ID (the ID is a link between a database for frequently updated 
information and the index for searching).

Optimally, it'd be great if we could just run the query vs the index AND 
the database, but I haven't found anything for doing that (using SQLite).

Would this be a custom Filter?  I've dealt with custom analyzers in the 
past, but that wouldn't be useful here.  Is there an existing filter 
where we can say "ignore these documents?"

Thanks in advance.

Trevor Watson
-----

Checked by AVG - www.avg.com
Version: 2012.0.1869 / Virus Database: 2092/4608 - Release Date: 11/10/11


RE: [Lucene.Net] Excluding search results

Posted by Moray McConnachie <mm...@oxford-analytica.com>.
We use a custom Collector for this purpose which does custom sorting and
filtering based on database criteria and relationships to other
documents. 

It works well, although it could get difficult in large document
universes where the filter list is large and the search is large too -
you could end up having an unpleasant choice between a database call
each time the Collect method is used or storing in-memory unfeasibly
large exclusion or filter lists.  In this scenario one might prefer to
take the extra effort to get your frequently updated information into
Lucene....

M.



-------------------------------------
Moray McConnachie
Director of IT    +44 1865 261 600
Oxford Analytica  http://www.oxan.com

-----Original Message-----
From: Trevor Watson [mailto:twatson@datassimilate.com] 
Sent: 10 November 2011 16:52
To: lucene-net-user@lucene.apache.org
Subject: [Lucene.Net] Excluding search results

We'd like to have the ability to exclude items from a search given the
ID (the ID is a link between a database for frequently updated
information and the index for searching).

Optimally, it'd be great if we could just run the query vs the index AND
the database, but I haven't found anything for doing that (using
SQLite).

Would this be a custom Filter?  I've dealt with custom analyzers in the
past, but that wouldn't be useful here.  Is there an existing filter
where we can say "ignore these documents?"

Thanks in advance.

Trevor Watson

---------------------------------------------------------
Disclaimer 

This message and any attachments are confidential and/or privileged. If this has been sent to you in error, please do not use, retain or disclose them, and contact the sender as soon as possible.

Oxford Analytica Ltd
Registered in England: No. 1196703
5 Alfred Street, Oxford
United Kingdom, OX1 4EH
---------------------------------------------------------


Re: [Lucene.Net] Excluding search results

Posted by Wyatt Barnett <wy...@gmail.com>.
You'd probably be better off attaching the IDs to the lucene documents
-- crossing the boundary will be expensive.

>From there it is pretty easy to use BooleanQuery and attach the ID(s)
you wish to filter as TermQueries with the
BooleanClause.Occour.MUST_NOT flag.

On Thu, Nov 10, 2011 at 11:51 AM, Trevor Watson
<tw...@datassimilate.com> wrote:
> We'd like to have the ability to exclude items from a search given the ID
> (the ID is a link between a database for frequently updated information and
> the index for searching).
>
> Optimally, it'd be great if we could just run the query vs the index AND the
> database, but I haven't found anything for doing that (using SQLite).
>
> Would this be a custom Filter?  I've dealt with custom analyzers in the
> past, but that wouldn't be useful here.  Is there an existing filter where
> we can say "ignore these documents?"
>
> Thanks in advance.
>
> Trevor Watson
>

Re: [Lucene.Net] Excluding search results

Posted by João Prado <jo...@gmail.com>.
I faced the same problem and my approach was encapsulate the result 
TopDocs in an YourObject and then remove/filter the undesirable ones 
using Linq:

         public IQueryable<YourObject> Search(string searchQuery)
         {
             TopDocs topDocs = 
Searcher.PerformSearch(GetIndexSearcher(), searchQuery);

             List<YourObject> list = new List<YourObject>();

             foreach (ScoreDoc scoreDoc in topDocs.scoreDocs)
             {
                 Document doc = GetIndexSearcher().Doc(scoreDoc.doc);
                 float score = scoreDoc.score;

                 list.Add(YourObjectWrapper.Wrap(doc, "venda", score));
             }

             return listaImoveis.AsQueryable();
         }

     public static class YourObjectWrapper
     {
         public static YourObject Wrap(Document doc, float score)
         {
             YourObject yourObject = new YourObject(doc.Get("Id"));
             yourObject.ResultScore = score;

             return yourObject;
         }
     }



Em 10/11/2011 14:51, Trevor Watson escreveu:
> We'd like to have the ability to exclude items from a search given the 
> ID (the ID is a link between a database for frequently updated 
> information and the index for searching).
>
> Optimally, it'd be great if we could just run the query vs the index 
> AND the database, but I haven't found anything for doing that (using 
> SQLite).
>
> Would this be a custom Filter?  I've dealt with custom analyzers in 
> the past, but that wouldn't be useful here.  Is there an existing 
> filter where we can say "ignore these documents?"
>
> Thanks in advance.
>
> Trevor Watson
>