Question about Solr Search and pages priority

Hi!

In our wiki we have many pages that needed be first in search results. How we can do it ?
I try to setup Main.SolrSearchConfig but I don’t know how to give weight to certain pages. I think it is good to use tags and give weight for tags (but how do this ? for standard properties such as name, title it is work)

You need to use either the Boost Query or the Boost Function parameters https://lucene.apache.org/solr/guide/6_6/the-dismax-query-parser.html#the-dismax-query-parser but they are not exposed in Main.SolrSearchConfig . You can try modifying Main.SolrSearchMacros page.

Hi,

Is no other way to add weight to tag class to Main.SolrSearchConfig ?

Config look like easy:

‘queryFields’: {
‘DOCUMENT’: ‘title^10.0 name^10.0
doccontent^2.0
objcontent^0.4 filename^0.4 attcontent^0.4 doccontentraw^0.4
author_display^0.08 creator_display^0.08
comment^0.016 attauthor_display^0.016 space^0.016’,
‘ATTACHMENT’: ‘filename^5.0 attcontent attauthor_display^0.2’,
‘OBJECT’: ‘objcontent’,
‘OBJECT_PROPERTY’: ‘propertyvalue’
},

But I don’t know how to add custom class to weights. If I add tag^100 then it not work.

You were not clear in your first post. Do you want to boost (give weight) to the tag field (no matter its value) or do you want to boost a specific tag value (e.g. push to the top of the result list the pages that have some specific tags like “news”)? The solution is completely different for each of them. My previous comment addresses the second use case. If you’re looking for the first use case then indeed, the solution is simpler. See http://extensions.xwiki.org/xwiki/bin/view/Extension/Solr+Search+Application#HFacetingonObjectProperties . It shows you how to facet the results based on tags. The tag field used for faceting can be used in queryFields also.

Hi,

Thank you. In my case two ways will be good. Add weight to tag is simpler for me.
But if I add ‘property.XWiki.TagClass.tags_string’ in facetFields then it works, but if I add property.XWiki.TagClass.tags_string^100 in queryFields then weight not work.

I tryied to add it in queryFields in different sections

‘queryFields’: {
‘DOCUMENT’: ‘title^10.0 name^10.0
doccontent^2.0
objcontent^0.4 filename^0.4 attcontent^0.4 doccontentraw^0.4
author_display^0.08 creator_display^0.08
comment^0.016 attauthor_display^0.016 space^0.016
property.XWiki.TagClass.tags_string^100.0’,
‘ATTACHMENT’: ‘filename^5.0 attcontent attauthor_display^0.2’,
‘OBJECT’: ‘property.XWiki.TagClass.tags_string^100.0’,
‘OBJECT_PROPERTY’: ‘property.XWiki.TagClass.tags_string^100.0’
},

But it not add weight to my search query for my page which use tag.

Try with property.XWiki.TagClass.tags. The “_string” suffix is appended automatically when the field appears in queryFields but not when the field appears in facetFields.

1 Like

Marius,

We were chatting about this the other day too. I thought I would add this here as @Aleksey2610 might be interested.

This solution only seems to perform case sensitive queries for me. I believe it’s because tags_string is the only field that actually holds the object property.

Is there a way to make it case insensitive?

Thanks,
Ben

The field types used in the Solr index dictate whether the search is case sensitive or insensitive. For instance the “String” type is case sensitive while the “text_general” type is case insensitive. Thus if you have a “name” field of type “String” and a “title” field of type “text_general” and you search for “Wiki” Solr will look for “Wiki” (exact match) in “name” and for “wiki” (lowecase) in “title”.

In the case of the tags property, property.XWiki.TagClass.tags_string is a dynamic field, and the “_string” suffix is mapped to the “String” type which is indeed case sensitive. See https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-search/xwiki-platform-search-solr/xwiki-platform-search-solr-server/xwiki-platform-search-solr-server-data/src/main/resources/xwiki/conf/managed-schema#L307

<dynamicField name="*_string" type="string" indexed="true" stored="true" multiValued="true" />

The tags property of XWiki.TagClass is of type Static List so it is indexed like this https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-search/xwiki-platform-search-solr/xwiki-platform-search-solr-api/src/main/java/org/xwiki/search/solr/internal/metadata/AbstractSolrMetadataExtractor.java#L419 . The display value is the same as the stored value so you have only the “_string” field in the Solr index.

In general the raw values of a static list are case sensitive, that’s why we index them as String. Tags are a special case. Note that the tags are also indexed in the objcontent field which is of type “text_general” but it also includes the content from other objects on the page so you can’t boost just the tags, you would boost all the objects on the page.

Marius,

Thank you very much for that detailed explanation! Very informative.

However, I’m not quite sure what the conclusion is. Is there an easy way to make tag searches case insensitive? It sounds like I need to modify the schema… Or maybe the query, not found an easy or elegant way to achieve this though.

Ben

One option is to add this line after https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwiki-platform-search/xwiki-platform-search-solr/xwiki-platform-search-solr-api/src/main/java/org/xwiki/search/solr/internal/metadata/AbstractSolrMetadataExtractor.java#L442

setPropertyValue(solrDocument, property, new TypedValue(rawValue, TypedValue.TEXT), locale);

This means indexing the Static List (raw) values both as “String” and as localized text. The match on localized text is case insensitive but not an exact match. For instance searching for “books” will match also “book”.

If you want case insensitive exact match then you need to define a dedicated type in the Solr schema, map a static or dynamic field to this type and modify the Java code to index the tags using this new field.

In any case, I don’t think you can achieve what you want without writing some Java code, unless you modify the Solr schema to map the dynamic *_string field to a different type but this will affect all properties that use it, not just tags, so I don’t think you want that.

Marius,

Perfect! Exactly what I want. I might implement this in my active pull request over Christmas along with the other changes I need to make. We can discuss further on GitHub if need be.

Thank you very much.
Ben