Developer Forum »
"Score" parameter yields no results - WAF Lucene IndexQuery
12 posts

Hi all, 

I'm facing some challenges, trying to understand the "Score" variable yielded on each search result by using a lucene index query. Basically what I'm trying to achieve is to implement a basic search result weight, using the Webnodes Lucene IndexQuery.

 

Webnodes versions tested: 1612, 1617.

 

 

I'm currently doing searches using my method below (included all parameters I use in case it matters).

Then, I iterate through the results filling up my own POCO class, trying to fetch the "Score" and the "ScorePercentage" variables.

I've even tried disabling fuzzy and turning on autofuzzy (q.AutoFuzzy = true), 

and disabling fuzzy entirely. 

But the "Score" variable (a float) is always "NaN", and the "ScorePercentage" (a byte) is always 0.

I use my search provider like this across several Webnodes installations, and I have not yet managed to get a >0 result on any of the search results yielded.

 

Do you have any tips as to how I can get positive score parameters on my search results?

Am I missing something? Any tips would be greatly appreciated.

 

 

private List DoWebnodesIndexSearch(string searchQuery)
        {           
            IndexQuery q = new IndexQuery();
			string fuzzySearchSimilarity = "0.8";
			if (FuzzySearch) SearchQuery = SearchQuery + "~" + fuzzySearchSimilarity; 
            if (ContentClassIdsOverride != null)
            {
                q.ClassIds = ContentClassIdsOverride;
            }
            if (SiteIdsOverride != null)
            {
                q.SiteIds = SiteIdsOverride;
            }
            q.BodySearch = searchQuery;
            q.AddSort(IndexField.ChangeDate, false);
            q.ProtectedContent = false;
            List searchResultList= WAFContext.Session.Search(q);
            return searchResultList;
        }

 

foreach (var nativeSearchResult in DoWebnodesIndexSearch(theQuery))
            {
                var someClass = new SomeClass
                {
                    ..
                    Relevance = nativeSearchResult.Score,
					RelevancePercent = nativeSearchResult.ScorePercent
					..
                };
			}

 

 

 

12 posts

I can see the lucene library utilized to create scores in the Search method below.

See the TopDocs class, retrieved by indexSearcher.Search(query, null, (pageIndex + 1) * pageSize):

 

 public List Search(Query query, Sort sort, int pageIndex, int pageSize, out int pageCount, out int totalCount)

        {

            TopDocs topDoc;

            List wDocs;

            if (!WAFRuntime.Installation.EnableTextIndex)

            {

                totalCount = 0;

                pageCount = 0;

                return new List();

            }

            lock (DataAccessObject._luceneLock)

            {

                IndexSearcher indexSearcher = null;

                try

                {

                    if (pageSize == 0)

                    {

                        pageSize = 1000000;

                    }

                    indexSearcher = new IndexSearcher(this.SearchIndexer.Directory, true);

                    if (sort == null)

                    {

                        topDoc = indexSearcher.Search(query, null, (pageIndex + 1) * pageSize);

                    }

                    else

                    {

                        topDoc = indexSearcher.Search(query, null, (pageIndex + 1) * pageSize, sort);

                    }

                    ScoreDoc[] scoreDocArray = topDoc.scoreDocs;

                    List wDocs1 = new List();

                    totalCount = topDoc.totalHits;

                    pageCount = (int)Math.Ceiling((double)totalCount / (double)pageSize);

                    int num = pageIndex * pageSize;

                    int num1 = num + pageSize;

                    if (num1 > totalCount)

                    {

                        num1 = totalCount;

                    }

                    for (int i = num; i < num1; i++)

                    {

                        WDoc wDoc = new WDoc()

                        {

                            Doc = indexSearcher.Doc(scoreDocArray[i].doc),
                            Score = scoreDocArray[i].score
                        };
                        wDocs1.Add(wDoc);
                    }
                    wDocs = wDocs1;
                }
                finally
                {
                    try
                    {
                        if (indexSearcher != null)
                        {
                            indexSearcher.Close();
                        }
                    }
                    catch
                    {
                    }
                }

            }

            return wDocs;

 

Which leads me to this method in the Lucene library:

http://lucene.apache.org/core/3_0_3/api/core/org/apache/lucene/search/Searcher.html#search(org.apache.lucene.search.Query, int)

 

Should yield score results on any entry matching the query, shouldn't it?

 

120 posts

Hi, the score value does work on standard searches. I'm not sure why you cannot see it. Could it be your custom sorting?

12 posts

Quote:

Hi, the score value does work on standard searches. I'm not sure why you cannot see it. Could it be your custom sorting?

 

Indeed it was.

By removing the changedate index field sort, the result yielded scores.

      //q.AddSort(IndexField.ChangeDate, false);

Thank you very much!

 

 

1