question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

About the problem of distinct under the field obtained by Lucene.net when querying

See original GitHub issue

I’m sorry to ask here, I really can’t find how to use the distinct function on lucene.net4.8 beta16. My idea is to construct query conditions first, then filter, and finally get the result of the query as Distinct For example, the current query field results are: 1,1,1,1,1,5,6,7,8,4,5,6,4,5,6,5,5,4 Distinct result: 1, 5, 6, 7, 8, 4

I read Lucene.net.grouping on the official website But the demo can’t run normally, I’m helpless, looking forward to your reply. Thanks!

This is my current code and the performance is horrible

`public static SearchFilterList SearchFilter(string keyword, int brandId, string spec = “”, string model = “”, bool isCas = false) { string[] fileds = { “name”, “supplierNo”, “alias”, “engname” }; BooleanQuery bq = new BooleanQuery();

        if (keyword.IsNullOrEmpty() && brandId > 0)
        {
            bq.Add(new TermQuery(new Term("brand", brandId.ToString())), Occur.MUST);
        }
        else if (!isCas)
        {
            var query = MultiFieldQueryParser.Parse(version, GetKeyword(keyword), fileds, new Occur[] { Occur.SHOULD, Occur.SHOULD, Occur.SHOULD, Occur.SHOULD }, analyzer);
            bq.Add(query, Occur.SHOULD);
            foreach (var item in fileds)
            {
                bq.Add(new RegexpQuery(new Term(item, $".*{keyword}.*")), Occur.SHOULD);
            }
        }
        else
        {
            bq.Add(new TermQuery(new Term("cas", keyword)), Occur.MUST);
        }
        BooleanFilter filter = null;
        if (brandId > 0)
        {
            if (filter == null) filter = new BooleanFilter();
            filter.Add(new FilterClause(new FieldCacheTermsFilter("brand", new[] { brandId.ToString() }), Occur.MUST));
        }
        if (!string.IsNullOrEmpty(spec))
        {
            if (filter == null) filter = new BooleanFilter();
            filter.Add(new FilterClause(new FieldCacheTermsFilter("spec", new[] { spec }), Occur.MUST));

        }
        if (!string.IsNullOrEmpty(model))
        {
            if (filter == null) filter = new BooleanFilter();
            filter.Add(new FilterClause(new FieldCacheTermsFilter("model", new[] { model }), Occur.MUST));
        }
        IndexSearcher searcher = new IndexSearcher(DirectoryReader.Open(direcotry));
        TopDocs docs = searcher.Search(bq, filter, 10000);
        if (docs == null)
        {
            return null;
        }

        ConcurrentQueue<int> brands = new ConcurrentQueue<int>();
        ConcurrentQueue<string> specs = new ConcurrentQueue<string>();
        ConcurrentQueue<string> models = new ConcurrentQueue<string>();
        Parallel.ForEach(docs.ScoreDocs, new ParallelOptions() { MaxDegreeOfParallelism = 8 }, sd =>
        {
            try
            {
                Document doc = searcher.Doc(sd.Doc);
                brands.Enqueue(doc.Get("brand").ToInt32());
                var specValue = doc.Get("spec");
                if (!string.IsNullOrEmpty(specValue))
                {
                    specs.Enqueue(specValue);
                }
                var modelValue = doc.Get("model");
                if (!string.IsNullOrEmpty(modelValue))
                {
                    models.Enqueue(modelValue);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        });
        var dto  = new Json.Dto.SearchFilterList()
        {
            Brands = brands.Distinct().AsParallel(),
            Specifications = specs.Distinct().AsParallel(),
            Models = models.Distinct().AsParallel()
        };
        return dto;
    }`

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
eladmargcommented, Oct 13, 2022

this is not an issue, and this is not questions & answers site. if you have questions, please ask them on stackoverflow

@NightOwl888, please close. thanks.

0reactions
mq00fccommented, Oct 13, 2022

The TestGroupingExtra.cs file I mentioned contains lots of examples of sorting in the context of groups.

Sorry I didn’t find any clue you said, here I am not using groupingsearch but boolean query,groupingsearch use filter data item,It has been done with your help,and I want to sort by similarity, but I can’t find it(This is a new query, groupingsearch is not used, sorry my english is not very good)

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Lucene.Net - Get distinct categories
I would like to get all distinct categories (get all documents and read a value of category field) by executing search query. Is...
Read more >
Namespace Lucene.Net.Search
In this example, the Query identifies all Documents that have the Field named "fieldName" containing the word "term" . BooleanQuery. Things start to...
Read more >
Tutorial | Apache Lucene.NET 4.8.0
We are going to create a console application that uses Lucene.NET to index three documents that each have two fields and then the...
Read more >
Autocomplete Lucene Query
I am currently trying to write an autocomplete feature using a lucene query that looks like this. LuceneQuery(Constants.Raven.Indexes.Players)
Read more >
Namespace Lucene.Net.Search.Similarities
This package contains the various ranking models that can be used in Lucene. The abstract class Similarity serves as the base for ranking...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found